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

Better recovery from a few index/tar errors #7972

Merged
merged 3 commits into from
Feb 23, 2022
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
7 changes: 5 additions & 2 deletions cabal-install/src/Distribution/Client/CmdUpdate.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE ViewPatterns #-}

Expand All @@ -13,6 +14,7 @@ module Distribution.Client.CmdUpdate (
) where

import Prelude ()
import Control.Exception
import Distribution.Client.Compat.Prelude

import Distribution.Client.NixStyleOptions
Expand Down Expand Up @@ -42,7 +44,7 @@ import Distribution.Client.Setup
import Distribution.Simple.Flag
( fromFlagOrDefault )
import Distribution.Simple.Utils
( die', notice, wrapText, writeFileAtomic, noticeNoWrap )
( die', notice, wrapText, writeFileAtomic, noticeNoWrap, warn )
import Distribution.Verbosity
( normal, lessVerbose )
import Distribution.Client.IndexUtils.Timestamp
Expand Down Expand Up @@ -209,7 +211,8 @@ updateRepo verbosity _updateFlags repoCtxt (repo, indexState) = do
case updated of
Sec.NoUpdates -> do
now <- getCurrentTime
setModificationTime (indexBaseName repo <.> "tar") now
setModificationTime (indexBaseName repo <.> "tar") now `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 at index-state " ++ prettyShow (IndexStateTime current_ts)
Expand Down
16 changes: 10 additions & 6 deletions cabal-install/src/Distribution/Client/IndexUtils.hs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ getSourcePackagesAtIndexState verbosity repoCtxt mb_idxState mb_activeRepos = do
" as explicitly requested (via command line / project configuration)"
return idxState
Nothing -> do
mb_idxState' <- readIndexTimestamp (RepoIndex repoCtxt r)
mb_idxState' <- readIndexTimestamp verbosity (RepoIndex repoCtxt r)
case mb_idxState' of
Nothing -> do
info verbosity "Using most recent state (could not read timestamp file)"
Expand Down Expand Up @@ -365,7 +365,9 @@ readRepoIndex :: Verbosity -> RepoContext -> Repo -> RepoIndexState
readRepoIndex verbosity repoCtxt repo idxState =
handleNotFound $ do
when (isRepoRemote repo) $ warnIfIndexIsOld =<< getIndexFileAge repo
updateRepoIndexCache verbosity (RepoIndex repoCtxt repo)
-- note that if this step fails due to a bad repocache, the the procedure can still succeed by reading from the existing cache, which is updated regardless.
updateRepoIndexCache verbosity (RepoIndex repoCtxt repo) `catchIO`
(\e -> warn verbosity $ "unable to update the repo index cache -- " ++ displayException e)
readPackageIndexCacheFile verbosity mkAvailablePackage
(RepoIndex repoCtxt repo)
idxState
Expand Down Expand Up @@ -1054,21 +1056,23 @@ writeIndexTimestamp index st
-- timestamp you would use to revert to this version
currentIndexTimestamp :: Verbosity -> RepoContext -> Repo -> IO Timestamp
currentIndexTimestamp verbosity repoCtxt r = do
mb_is <- readIndexTimestamp (RepoIndex repoCtxt r)
mb_is <- readIndexTimestamp verbosity (RepoIndex repoCtxt r)
case mb_is of
Just (IndexStateTime ts) -> return ts
_ -> do
(_,_,isi) <- readRepoIndex verbosity repoCtxt r IndexStateHead
return (isiHeadTime isi)

-- | Read the 'IndexState' from the filesystem
readIndexTimestamp :: Index -> IO (Maybe RepoIndexState)
readIndexTimestamp index
readIndexTimestamp :: Verbosity -> Index -> IO (Maybe RepoIndexState)
readIndexTimestamp verbosity index
= fmap simpleParsec (readFile (timestampFile index))
`catchIO` \e ->
if isDoesNotExistError e
then return Nothing
else ioError e
else do
warn verbosity $ "Warning: could not read current index timestamp: " ++ displayException e
return Nothing
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we pass in verbosity and also use warn here?


-- | Optimise sharing of equal values inside 'Cache'
--
Expand Down