@@ -72,6 +72,7 @@ data FetchException
7272 | CouldNotParsePackageSelectors [String ]
7373 | UnknownPackageNames (Set PackageName )
7474 | UnknownPackageIdentifiers (HashSet PackageIdentifierRevision ) String
75+ Bool -- Do we use any 00-index.tar.gz indices? Just used for more informative error messages
7576 deriving Typeable
7677instance Exception FetchException
7778
@@ -97,10 +98,11 @@ instance Show FetchException where
9798 show (UnknownPackageNames names) =
9899 " The following packages were not found in your indices: " ++
99100 intercalate " , " (map packageNameString $ Set. toList names)
100- show (UnknownPackageIdentifiers idents suggestions) =
101+ show (UnknownPackageIdentifiers idents suggestions uses00Index ) =
101102 " The following package identifiers were not found in your indices: " ++
102103 intercalate " , " (map packageIdentifierRevisionString $ HashSet. toList idents) ++
103- (if null suggestions then " " else " \n " ++ suggestions)
104+ (if null suggestions then " " else " \n " ++ suggestions) ++
105+ (if uses00Index then " \n\n You seem to be using a legacy 00-index.tar.gz tarball.\n Consider changing your configuration to use a 01-index.tar.gz file.\n Alternatively, you can set the ignore-revision-mismatch setting to true.\n For more information, see: https://github.com/commercialhaskell/stack/issues/3520" else " " )
104106
105107-- | Fetch packages into the cache without unpacking
106108fetchPackages :: HasConfig env => Set PackageIdentifier -> RIO env ()
@@ -202,12 +204,21 @@ resolvePackages mSnapshotDef idents0 names0 = do
202204 go >>= either throwM return
203205 Right x -> return x
204206 where
205- go = r <$> resolvePackagesAllowMissing mSnapshotDef idents0 names0
206- r (missingNames, missingIdents, idents)
207+ go = r <$> getUses00Index <*> resolvePackagesAllowMissing mSnapshotDef idents0 names0
208+ r uses00Index (missingNames, missingIdents, idents)
207209 | not $ Set. null missingNames = Left $ UnknownPackageNames missingNames
208- | not $ HashSet. null missingIdents = Left $ UnknownPackageIdentifiers missingIdents " "
210+ | not $ HashSet. null missingIdents = Left $ UnknownPackageIdentifiers missingIdents " " uses00Index
209211 | otherwise = Right idents
210212
213+ -- | Does the configuration use a 00-index.tar.gz file for indices?
214+ -- See <https://github.com/commercialhaskell/stack/issues/3520>
215+ getUses00Index :: HasConfig env => RIO env Bool
216+ getUses00Index =
217+ any is00 <$> view packageIndicesL
218+ where
219+ is00 :: PackageIndex -> Bool
220+ is00 index = " 00-index.tar.gz" `T.isInfixOf` indexLocation index
221+
211222-- | Turn package identifiers and package names into a list of
212223-- @ResolvedPackage@s. Returns any unresolved names and
213224-- identifier. These are considered unresolved even if the only
@@ -256,23 +267,30 @@ resolvePackagesAllowMissing mSnapshotDef idents0 names0 = do
256267 (missingNames, idents1) = partitionEithers $ map
257268 (\ name -> maybe (Left name) Right (getNamed name))
258269 (Set. toList names0)
270+ config <- view configL
259271 let (missingIdents, resolved) =
260272 partitionEithers
261- $ map (\ pir -> maybe (Left pir) Right (lookupResolvedPackage pir cache))
273+ $ map (\ pir -> maybe (Left pir) Right (lookupResolvedPackage config pir cache))
262274 $ idents0 <> idents1
263275 return (Set. fromList missingNames, HashSet. fromList missingIdents, resolved)
264276
265- lookupResolvedPackage :: PackageIdentifierRevision -> PackageCache PackageIndex -> Maybe ResolvedPackage
266- lookupResolvedPackage (PackageIdentifierRevision ident@ (PackageIdentifier name version) cfi) (PackageCache cache) = do
277+ lookupResolvedPackage :: Config -> PackageIdentifierRevision -> PackageCache PackageIndex -> Maybe ResolvedPackage
278+ lookupResolvedPackage config (PackageIdentifierRevision ident@ (PackageIdentifier name version) cfi) (PackageCache cache) = do
267279 (index, mdownload, files) <- HashMap. lookup name cache >>= HashMap. lookup version
280+ let moffsetSize =
281+ case cfi of
282+ CFILatest -> Just $ snd $ NE. last files
283+ CFIHash _msize hash' -> -- TODO check size?
284+ lookup hash'
285+ $ concatMap (\ (hashes, x) -> map (, x) hashes)
286+ $ NE. toList files
287+ CFIRevision rev -> fmap snd $ listToMaybe $ drop (fromIntegral rev) $ NE. toList files
268288 offsetSize <-
269- case cfi of
270- CFILatest -> Just $ snd $ NE. last files
271- CFIHash _msize hash' -> -- TODO check size?
272- lookup hash'
273- $ concatMap (\ (hashes, x) -> map (, x) hashes)
274- $ NE. toList files
275- CFIRevision rev -> fmap snd $ listToMaybe $ drop (fromIntegral rev) $ NE. toList files
289+ case moffsetSize of
290+ Just x -> Just x
291+ Nothing
292+ | configIgnoreRevisionMismatch config -> Just $ snd $ NE. last files
293+ | otherwise -> Nothing
276294 Just ResolvedPackage
277295 { rpIdent = ident
278296 , rpDownload = mdownload
@@ -365,9 +383,10 @@ withCabalLoader inner = do
365383 _ <- getPackageCaches
366384 return ()
367385 return (False , doLookup ident)
368- else return (toUpdate,
369- throwIO $ UnknownPackageIdentifiers
370- (HashSet. singleton ident) (T. unpack suggestions))
386+ else do
387+ uses00Index <- unliftIO u getUses00Index
388+ return (toUpdate, throwIO $ UnknownPackageIdentifiers
389+ (HashSet. singleton ident) (T. unpack suggestions) uses00Index)
371390 inner doLookup
372391
373392lookupPackageIdentifierExact
@@ -376,7 +395,8 @@ lookupPackageIdentifierExact
376395 -> PackageCache PackageIndex
377396 -> m (Maybe ByteString )
378397lookupPackageIdentifierExact identRev cache = do
379- forM (lookupResolvedPackage identRev cache) $ \ rp -> do
398+ config <- view configL
399+ forM (lookupResolvedPackage config identRev cache) $ \ rp -> do
380400 [bs] <- withCabalFiles (indexName (rpIndex rp)) [(rp, () )] $ \ _ _ bs -> return bs
381401 return bs
382402
0 commit comments