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

Reject index-states after last known index-state #8944

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,6 @@ bench.html

# Emacs
.projectile

# I'm unsure how to ignore these generated golden files
cabal-testsuite/PackageTests/NewUpdate/RejectFutureIndexStates/cabal.out
31 changes: 19 additions & 12 deletions cabal-install/src/Distribution/Client/CmdUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ import Distribution.Simple.Command
import System.FilePath (dropExtension, (<.>))

import Distribution.Client.Errors
import Distribution.Client.IndexUtils.Timestamp (nullTimestamp)
import Distribution.Client.IndexUtils.Timestamp (Timestamp (NoTimestamp))
import qualified Hackage.Security.Client as Sec

updateCommand :: CommandUI (NixStyleFlags ())
Expand Down Expand Up @@ -257,18 +257,19 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
updateRepoIndexCache verbosity (RepoIndex repoCtxt repo)
RepoSecure{} -> repoContextWithSecureRepo repoCtxt repo $ \repoSecure -> do
let index = RepoIndex repoCtxt repo
-- NB: This may be a nullTimestamp if we've never updated before
current_ts <- currentIndexTimestamp (lessVerbose verbosity) repoCtxt repo
-- NB: This may be a NoTimestamp if we've never updated before
current_ts <- currentIndexTimestamp (lessVerbose verbosity) index
-- NB: always update the timestamp, even if we didn't actually
-- download anything
writeIndexTimestamp index indexState
ce <-
if repoContextIgnoreExpiry repoCtxt
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

updated <- do
ce <-
if repoContextIgnoreExpiry repoCtxt
then Just <$> getCurrentTime
else return Nothing
Sec.uncheckClientErrors $ Sec.checkForUpdates repoSecure ce

let rname = remoteRepoName (repoRemote repo)

-- Update cabal's internal index as well so that it's not out of sync
Expand All @@ -277,14 +278,20 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
Sec.NoUpdates -> do
now <- getCurrentTime
setModificationTime (indexBaseName repo <.> "tar") now
`catchIO` (\e -> warn verbosity $ "Could not set modification time of index tarball -- " ++ displayException e)
`catchIO` \e ->
warn verbosity $ "Could not set modification time of index tarball -- " ++ displayException e
noticeNoWrap verbosity $
"Package list of " ++ prettyShow rname ++ " is up to date."
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.
new_ts <- currentIndexTimestamp (lessVerbose verbosity) index

noticeNoWrap verbosity $
"The index-state is set to " ++ prettyShow (IndexStateTime new_ts) ++ "."

Expand All @@ -294,7 +301,7 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do

-- 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 /= nullTimestamp && new_ts /= current_ts) $
when (current_ts /= NoTimestamp && new_ts /= current_ts) $
noticeNoWrap verbosity $
"To revert to previous state run:\n"
++ " cabal v2-update '"
Expand Down
21 changes: 21 additions & 0 deletions cabal-install/src/Distribution/Client/Errors.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ import Data.ByteString (ByteString)
import qualified Data.ByteString.Base16 as Base16
import qualified Data.ByteString.Char8 as BS8
import Data.List (groupBy)
import Distribution.Client.IndexUtils.Timestamp
import Distribution.Client.Types.Repo
import Distribution.Client.Types.RepoName (RepoName (..))
import Distribution.Compat.Prelude
import Distribution.Deprecated.ParseUtils (PWarning, showPWarning)
import Distribution.Package
Expand Down Expand Up @@ -179,6 +182,8 @@ data CabalInstallException
| FreezeException String
| PkgSpecifierException [String]
| CorruptedIndexCache String
| UnusableIndexState RemoteRepo Timestamp Timestamp
| MissingPackageList RemoteRepo
deriving (Show, Typeable)

exceptionCodeCabalInstall :: CabalInstallException -> Int
Expand Down Expand Up @@ -327,6 +332,8 @@ exceptionCodeCabalInstall e = case e of
FreezeException{} -> 7156
PkgSpecifierException{} -> 7157
CorruptedIndexCache{} -> 7158
UnusableIndexState{} -> 7159
MissingPackageList{} -> 7160

exceptionMessageCabalInstall :: CabalInstallException -> String
exceptionMessageCabalInstall e = case e of
Expand Down Expand Up @@ -828,6 +835,20 @@ exceptionMessageCabalInstall e = case e of
FreezeException errs -> errs
PkgSpecifierException errorStr -> unlines errorStr
CorruptedIndexCache str -> str
UnusableIndexState repoRemote maxFound requested ->
"Latest known index-state for '"
++ unRepoName (remoteRepoName repoRemote)
++ "' ("
++ prettyShow maxFound
++ ") is older than the requested index-state ("
++ prettyShow requested
++ ").\nRun 'cabal update' or set the index-state to a value at or before "
++ prettyShow maxFound
++ "."
MissingPackageList repoRemote ->
"The package list for '"
++ unRepoName (remoteRepoName repoRemote)
++ "' does not exist. Run 'cabal update' to download it."

instance Exception (VerboseException CabalInstallException) where
displayException :: VerboseException CabalInstallException -> [Char]
Expand Down
Loading
Loading