Skip to content

Commit

Permalink
Fix the timestamp shown during cabal update
Browse files Browse the repository at this point in the history
Passing an index-state timestamp to cabal update currently makes it
write a message saying the index has been updated to the *previous*
timestamp.

    $ cabal update hackage.haskell.org,2016-09-24T17:47:48Z
    Downloading the latest package list from hackage.haskell.org
    Package list of hackage.haskell.org is up to date at index-state 2022-01-27T12:59:23Z

This is because of a confusion between downloading the index and setting
the index state. These are independent actions.

This patch makes separates the two messages (updating the index and
updating the index-state timestamp) and makes sure the right timestamp
is printed.
  • Loading branch information
andreabedini committed Jan 27, 2022
1 parent 0abbe37 commit eef2219
Showing 1 changed file with 15 additions and 15 deletions.
30 changes: 15 additions & 15 deletions cabal-install/src/Distribution/Client/CmdUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ import Distribution.Simple.Utils
( die', notice, wrapText, writeFileAtomic, noticeNoWrap )
import Distribution.Verbosity
( normal, lessVerbose )
import Distribution.Client.IndexUtils.Timestamp
import Distribution.Client.IndexUtils.IndexState
import Distribution.Client.IndexUtils
( updateRepoIndexCache, Index(..), writeIndexTimestamp
Expand Down Expand Up @@ -201,7 +200,8 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
then Just `fmap` getCurrentTime
else return Nothing
updated <- Sec.uncheckClientErrors $ Sec.checkForUpdates repoSecure ce

-- this resolves indexState (which could be HEAD) into a timestamp
new_ts <- currentIndexTimestamp (lessVerbose verbosity) repoCtxt repo
let rname = remoteRepoName (repoRemote repo)

-- Update cabal's internal index as well so that it's not out of sync
Expand All @@ -211,20 +211,20 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
now <- getCurrentTime
setModificationTime (indexBaseName repo <.> "tar") now
noticeNoWrap verbosity $
"Package list of " ++ prettyShow rname ++
" is up to date at index-state " ++ prettyShow (IndexStateTime current_ts)
"Package list of " ++ prettyShow rname ++ " is up to date."

Sec.HasUpdates -> do
updateRepoIndexCache verbosity index
new_ts <- currentIndexTimestamp (lessVerbose verbosity) repoCtxt repo
noticeNoWrap verbosity $
"Updated package list of " ++ prettyShow rname ++
" to the index-state " ++ 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.
when (current_ts /= nullTimestamp) $
noticeNoWrap verbosity $
"To revert to previous state run:\n" ++
" cabal v2-update '" ++ prettyShow (UpdateRequest rname (IndexStateTime current_ts)) ++ "'\n"
"Package list of " ++ prettyShow rname ++ " has been updated."

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.
when (new_ts /= current_ts) $
noticeNoWrap verbosity $
"To revert to previous state run:\n" ++
" cabal v2-update '" ++ prettyShow (UpdateRequest rname (IndexStateTime current_ts)) ++ "'\n"

0 comments on commit eef2219

Please sign in to comment.