diff --git a/cabal-install/src/Distribution/Client/CmdUpdate.hs b/cabal-install/src/Distribution/Client/CmdUpdate.hs index c0f4e05a137..5938d28c574 100644 --- a/cabal-install/src/Distribution/Client/CmdUpdate.hs +++ b/cabal-install/src/Distribution/Client/CmdUpdate.hs @@ -28,6 +28,7 @@ import Distribution.Client.HttpUtils import Distribution.Client.IndexUtils ( Index (..) , currentIndexTimestamp + , getIndexHeadTimestamp , indexBaseName , updatePackageIndexCacheFile , updateRepoIndexCache @@ -280,30 +281,57 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do setModificationTime (indexBaseName repo <.> "tar") now `catchIO` \e -> warn verbosity $ "Could not set modification time of index tarball -- " ++ displayException e + head_ts <- getIndexHeadTimestamp verbosity index noticeNoWrap verbosity $ - "Package list of " ++ prettyShow rname ++ " is up to date." + "The repository " ++ prettyShow rname ++ " is up to date. Its most recent known index-state is " ++ prettyShow head_ts ++ "." + noticeNoWrap verbosity $ + "The default index-state for the repository " + ++ prettyShow rname + ++ " has been updated to " + ++ prettyShow indexState + ++ "." + -- This resolves indexState (which could be HEAD) into a timestamp. + -- This could be null but the above guarantees we have an updated index. + revertMessage index current_ts Sec.HasUpdates -> do updateRepoIndexCache verbosity index - noticeNoWrap verbosity $ - "Package list of " ++ prettyShow rname ++ " has been updated." - - -- This resolves indexState (which could be HEAD) into a timestamp - -- This could be null but should not be, since the above guarantees - -- we have an updated index. + head_ts <- getIndexHeadTimestamp verbosity index + -- This resolves indexState (which could be HEAD) into a timestamp + -- This could be null but should not be, since the above guarantees + -- we have an updated index. + new_ts <- currentIndexTimestamp (lessVerbose verbosity) index + if new_ts == head_ts + then + noticeNoWrap verbosity $ + "The most recent known index-state and the default index-state timestamp for the repository " + ++ prettyShow rname + ++ " have both been updated to " + ++ prettyShow (IndexStateTime new_ts) + ++ "." + else do + noticeNoWrap verbosity $ + "The most recent known index-state for the repository " + ++ prettyShow rname + ++ " has been updated to " + ++ prettyShow head_ts + ++ "." + noticeNoWrap verbosity $ + "The default index-state for the repository " + ++ prettyShow rname + ++ " has been updated to " + ++ prettyShow indexState + ++ "." + revertMessage index current_ts + where + revertMessage index current_ts = do + -- This resolves indexState (which could be HEAD) into a timestamp. + -- This could be null if we have never run cabal update before. new_ts <- currentIndexTimestamp (lessVerbose verbosity) index - - noticeNoWrap verbosity $ - "The index-state is set to " ++ prettyShow (IndexStateTime new_ts) ++ "." - - -- TODO: This will print multiple times if there are multiple - -- repositories: main problem is we don't have a way of updating - -- a specific repo. Once we implement that, update this. - -- In case current_ts is a valid timestamp different from new_ts, let -- the user know how to go back to current_ts when (current_ts /= NoTimestamp && new_ts /= current_ts) $ noticeNoWrap verbosity $ - "To revert to previous state run:\n" - ++ " cabal v2-update '" - ++ prettyShow (UpdateRequest rname (IndexStateTime current_ts)) - ++ "'\n" + unlines + [ "To revert to previous state run:" + , " cabal v2-update '" ++ prettyShow (UpdateRequest (repoName repo) (IndexStateTime current_ts)) ++ "'" + ] diff --git a/cabal-install/src/Distribution/Client/IndexUtils.hs b/cabal-install/src/Distribution/Client/IndexUtils.hs index 2dc7d37e29c..07dbe3d32bd 100644 --- a/cabal-install/src/Distribution/Client/IndexUtils.hs +++ b/cabal-install/src/Distribution/Client/IndexUtils.hs @@ -40,6 +40,7 @@ module Distribution.Client.IndexUtils , updatePackageIndexCacheFile , writeIndexTimestamp , currentIndexTimestamp + , getIndexHeadTimestamp , BuildTreeRefType (..) , refTypeFromTypeCode , typeCodeFromRefType @@ -973,6 +974,10 @@ getIndexCache :: Verbosity -> Index -> RepoIndexState -> IO (Cache, IndexStateIn getIndexCache verbosity index idxState = filterCache idxState <$> readIndexCache verbosity index +getIndexHeadTimestamp :: Verbosity -> Index -> IO Timestamp +getIndexHeadTimestamp verbosity index = + cacheHeadTs <$> readIndexCache verbosity index + packageIndexFromCache :: Package pkg => Verbosity @@ -1189,7 +1194,7 @@ currentIndexTimestamp verbosity index = do return ts -- Otherwise used the head time as stored in the index cache _otherwise -> - fmap (isiHeadTime . snd) (getIndexCache verbosity index IndexStateHead) + getIndexHeadTimestamp verbosity index `catchIO` \e -> if isDoesNotExistError e then return NoTimestamp diff --git a/cabal-testsuite/PackageTests/NewUpdate/RejectFutureIndexStates/cabal.test.hs b/cabal-testsuite/PackageTests/NewUpdate/RejectFutureIndexStates/cabal.test.hs index ca26a482d16..eb80e0b50ee 100644 --- a/cabal-testsuite/PackageTests/NewUpdate/RejectFutureIndexStates/cabal.test.hs +++ b/cabal-testsuite/PackageTests/NewUpdate/RejectFutureIndexStates/cabal.test.hs @@ -10,8 +10,7 @@ main = cabalTest $ withProjectFile "cabal.project" $ withRemoteRepo "repo" $ do . resultOutput <$> recordMode DoNotRecord (cabal' "update" []) -- update golden output with actual timestamp - shell "cp" ["cabal.out.in", "cabal.out"] - shell "sed" ["-i''", "-e", "s/REPLACEME/" <> output <> "/g", "cabal.out"] + shell "sed" ["-e", "s/REPLACEME/" <> output <> "/g; w cabal.out", "cabal.out.in"] -- This shall fail with an error message as specified in `cabal.out` fails $ cabal "build" ["--index-state=4000-01-01T00:00:00Z", "fake-pkg"] -- This shall fail by not finding the package, what indicates that it diff --git a/cabal-testsuite/PackageTests/NewUpdate/UpdateIndexState/update-index-state.out b/cabal-testsuite/PackageTests/NewUpdate/UpdateIndexState/update-index-state.out index d63c65ec921..430563de31c 100644 --- a/cabal-testsuite/PackageTests/NewUpdate/UpdateIndexState/update-index-state.out +++ b/cabal-testsuite/PackageTests/NewUpdate/UpdateIndexState/update-index-state.out @@ -1,12 +1,12 @@ # cabal update Downloading the latest package list from repository.localhost -Package list of repository.localhost is up to date. -The index-state is set to 2016-09-24T17:47:48Z. +The repository repository.localhost is up to date. Its most recent known index-state is 2024-01-19T07:22:23Z. +The default index-state for the repository repository.localhost has been updated to 2016-09-24T17:47:48Z. To revert to previous state run: cabal v2-update 'repository.localhost,2022-01-28T02:36:41Z' # cabal update Downloading the latest package list from repository.localhost -Package list of repository.localhost is up to date. -The index-state is set to 2022-01-28T02:36:41Z. +The repository repository.localhost is up to date. Its most recent known index-state is 2024-01-19T07:22:23Z. +The default index-state for the repository repository.localhost has been updated to 2022-01-28T02:36:41Z. To revert to previous state run: cabal v2-update 'repository.localhost,2016-09-24T17:47:48Z' diff --git a/cabal-testsuite/PackageTests/NewUpdate/UpdateIndexState/update-index-state.test.hs b/cabal-testsuite/PackageTests/NewUpdate/UpdateIndexState/update-index-state.test.hs index 2be563c6bec..4375d34a4e3 100644 --- a/cabal-testsuite/PackageTests/NewUpdate/UpdateIndexState/update-index-state.test.hs +++ b/cabal-testsuite/PackageTests/NewUpdate/UpdateIndexState/update-index-state.test.hs @@ -4,9 +4,10 @@ main = cabalTest $ withRemoteRepo "repo" $ do -- The _first_ update call causes a warning about missing mirrors, the warning -- is platform-dependent and it's not part of the test expectations, so we -- check the output manually. - res <- recordMode DoNotRecord $ - cabal' "update" ["repository.localhost,2022-01-28T02:36:41Z"] - assertOutputContains "The index-state is set to 2022-01-28T02:36:41Z" res + res <- + recordMode DoNotRecord $ + cabal' "update" ["repository.localhost,2022-01-28T02:36:41Z"] + assertOutputContains "The default index-state for the repository repository.localhost has been updated to" res assertOutputDoesNotContain "revert" res cabal "update" ["repository.localhost,2016-09-24T17:47:48Z"] cabal "update" ["repository.localhost,2022-01-28T02:36:41Z"]