Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve cabal update message #9521

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions cabal-install/src/Distribution/Client/CmdUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import Distribution.Client.HttpUtils
import Distribution.Client.IndexUtils
( Index (..)
, currentIndexTimestamp
, getIndexHeadTimestamp
, indexBaseName
, updatePackageIndexCacheFile
, updateRepoIndexCache
Expand Down Expand Up @@ -280,24 +281,26 @@ 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."
"Package list of " ++ prettyShow rname ++ " is up to date to " ++ prettyShow head_ts ++ "."
andreabedini marked this conversation as resolved.
Show resolved Hide resolved
Sec.HasUpdates -> do
updateRepoIndexCache verbosity index
head_ts <- getIndexHeadTimestamp verbosity index
noticeNoWrap verbosity $
"Package list of " ++ prettyShow rname ++ " has been updated."
"Package list of " ++ prettyShow rname ++ " has been updated to " ++ prettyShow head_ts ++ "."

-- 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

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.
"The global index-state for "
++ prettyShow rname
++ " now resolves to "
andreabedini marked this conversation as resolved.
Show resolved Hide resolved
++ prettyShow (IndexStateTime new_ts)
++ "."

-- In case current_ts is a valid timestamp different from new_ts, let
-- the user know how to go back to current_ts
Expand Down
7 changes: 6 additions & 1 deletion cabal-install/src/Distribution/Client/IndexUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ module Distribution.Client.IndexUtils
, updatePackageIndexCacheFile
, writeIndexTimestamp
, currentIndexTimestamp
, getIndexHeadTimestamp
, BuildTreeRefType (..)
, refTypeFromTypeCode
, typeCodeFromRefType
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Package list of repository.localhost is up to date to 2023-12-15T04:30:20Z.
The global index-state for repository.localhost now resolves 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.
Package list of repository.localhost is up to date to 2023-12-15T04:30:20Z.
The global index-state for repository.localhost now resolves to 2022-01-28T02:36:41Z.
To revert to previous state run:
cabal v2-update 'repository.localhost,2016-09-24T17:47:48Z'
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ main = cabalTest $ withRemoteRepo "repo" $ do
-- 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
assertOutputContains "The global index-state for repository.localhost now resolves to 2022-01-28T02:36:41Z." res
assertOutputDoesNotContain "revert" res
cabal "update" ["repository.localhost,2016-09-24T17:47:48Z"]
cabal "update" ["repository.localhost,2022-01-28T02:36:41Z"]
Loading