Skip to content

Commit 14727bc

Browse files
authored
Merge pull request #8697 from haskell/gb/no-warn-missing-tarball-download
elim warning spam from #8500
2 parents 8aad429 + ffa9127 commit 14727bc

File tree

2 files changed

+24
-20
lines changed

2 files changed

+24
-20
lines changed

cabal-install/src/Distribution/Client/FetchUtils.hs

+21-17
Original file line numberDiff line numberDiff line change
@@ -131,25 +131,29 @@ verifyFetchedTarball verbosity repoCtxt repo pkgid =
131131
case res of
132132
Left e -> warn verbosity ("Error verifying fetched tarball " ++ file ++ ", will redownload: " ++ show (e :: SomeException)) >> pure False
133133
Right b -> pure b
134-
in handleError $ case repo of
135-
-- a secure repo has hashes we can compare against to confirm this is the correct file.
136-
RepoSecure{} ->
137-
repoContextWithSecureRepo repoCtxt repo $ \repoSecure ->
138-
Sec.withIndex repoSecure $ \callbacks ->
139-
let warnAndFail s = warn verbosity ("Fetched tarball " ++ file ++ " does not match server, will redownload: " ++ s) >> return False
140-
-- the do block in parens is due to dealing with the checked exceptions mechanism.
141-
in (do fileInfo <- Sec.indexLookupFileInfo callbacks pkgid
142-
sz <- Sec.FileLength . fromInteger <$> getFileSize file
143-
if sz /= Sec.fileInfoLength (Sec.trusted fileInfo)
144-
then warnAndFail "file length mismatch"
145-
else do
146-
res <- Sec.compareTrustedFileInfo (Sec.trusted fileInfo) <$> Sec.computeFileInfo (Sec.Path file :: Sec.Path Sec.Absolute)
147-
if res
148-
then pure True
149-
else warnAndFail "file hash mismatch")
134+
in handleError $ do
135+
exists <- doesFileExist file
136+
if not exists
137+
then return False
138+
else case repo of
139+
-- a secure repo has hashes we can compare against to confirm this is the correct file.
140+
RepoSecure{} ->
141+
repoContextWithSecureRepo repoCtxt repo $ \repoSecure ->
142+
Sec.withIndex repoSecure $ \callbacks ->
143+
let warnAndFail s = warn verbosity ("Fetched tarball " ++ file ++ " does not match server, will redownload: " ++ s) >> return False
144+
-- the do block in parens is due to dealing with the checked exceptions mechanism.
145+
in (do fileInfo <- Sec.indexLookupFileInfo callbacks pkgid
146+
sz <- Sec.FileLength . fromInteger <$> getFileSize file
147+
if sz /= Sec.fileInfoLength (Sec.trusted fileInfo)
148+
then warnAndFail "file length mismatch"
149+
else do
150+
res <- Sec.compareTrustedFileInfo (Sec.trusted fileInfo) <$> Sec.computeFileInfo (Sec.Path file :: Sec.Path Sec.Absolute)
151+
if res
152+
then pure True
153+
else warnAndFail "file hash mismatch")
150154
`Sec.catchChecked` (\(e :: Sec.InvalidPackageException) -> warnAndFail (show e))
151155
`Sec.catchChecked` (\(e :: Sec.VerificationError) -> warnAndFail (show e))
152-
_ -> pure True
156+
_ -> pure True
153157

154158
-- | Fetch a package if we don't have it already.
155159
--

cabal-install/src/Distribution/Client/ProjectPlanning.hs

+3-3
Original file line numberDiff line numberDiff line change
@@ -935,7 +935,7 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
935935
_ -> Right (pkgid, repo)
936936
| (pkgid, RepoTarballPackage repo _ _) <- allPkgLocations ]
937937

938-
(repoTarballPkgsWithMetadata, repoTarballPkgsToRedownload) <- fmap partitionEithers $
938+
(repoTarballPkgsWithMetadata, repoTarballPkgsToDownloadWithMeta) <- fmap partitionEithers $
939939
liftIO $ withRepoCtx $ \repoctx -> forM repoTarballPkgsWithMetadataUnvalidated $
940940
\x@(pkg, repo) -> verifyFetchedTarball verbosity repoctx repo pkg >>= \b -> case b of
941941
True -> return $ Left x
@@ -944,7 +944,7 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
944944
-- For tarballs from repos that do not have hashes available we now have
945945
-- to check if the packages were downloaded already.
946946
--
947-
(repoTarballPkgsToDownload',
947+
(repoTarballPkgsToDownloadWithNoMeta,
948948
repoTarballPkgsDownloaded)
949949
<- fmap partitionEithers $
950950
liftIO $ sequence
@@ -954,7 +954,7 @@ getPackageSourceHashes verbosity withRepoCtx solverPlan = do
954954
Just tarball -> return (Right (pkgid, tarball))
955955
| (pkgid, repo) <- repoTarballPkgsWithoutMetadata ]
956956

957-
let repoTarballPkgsToDownload = repoTarballPkgsToRedownload ++ repoTarballPkgsToDownload'
957+
let repoTarballPkgsToDownload = repoTarballPkgsToDownloadWithMeta ++ repoTarballPkgsToDownloadWithNoMeta
958958
(hashesFromRepoMetadata,
959959
repoTarballPkgsNewlyDownloaded) <-
960960
-- Avoid having to initialise the repository (ie 'withRepoCtx') if we

0 commit comments

Comments
 (0)