@@ -1167,23 +1167,27 @@ readIndexCache verbosity index = do
11671167-- 'dieWithException's if it fails again). Throws IOException if any arise.
11681168readNoIndexCache :: Verbosity -> Index -> IO NoIndexCache
11691169readNoIndexCache verbosity index = do
1170- cacheOrFail <- readNoIndexCache' index
1170+ cacheOrFail <- readNoIndexCache' verbosity index
11711171 case cacheOrFail of
11721172 Left msg -> do
11731173 warn verbosity $
11741174 concat
1175- [ " Parsing the index cache failed ("
1175+ [ " Parsing the index cache for repo \" "
1176+ , unRepoName (repoName repo)
1177+ , " \" failed ("
11761178 , msg
11771179 , " ). "
11781180 , " Trying to regenerate the index cache..."
11791181 ]
11801182
11811183 updatePackageIndexCacheFile verbosity index
11821184
1183- either (dieWithException verbosity . CorruptedIndexCache ) return =<< readNoIndexCache' index
1185+ either (dieWithException verbosity . CorruptedIndexCache ) return =<< readNoIndexCache' verbosity index
11841186
11851187 -- we don't hash cons local repository cache, they are hopefully small
11861188 Right res -> return res
1189+ where
1190+ RepoIndex _ctxt repo = index
11871191
11881192-- | Read the 'Index' cache from the filesystem. Throws IO exceptions
11891193-- if any arise and returns Left on invalid input.
@@ -1194,8 +1198,12 @@ readIndexCache' index
11941198 | otherwise =
11951199 Right . read00IndexCache <$> BSS. readFile (cacheFile index)
11961200
1197- readNoIndexCache' :: Index -> IO (Either String NoIndexCache )
1198- readNoIndexCache' index = structuredDecodeFileOrFail (cacheFile index)
1201+ readNoIndexCache' :: Verbosity -> Index -> IO (Either String NoIndexCache )
1202+ readNoIndexCache' verbosity index = do
1203+ exists <- doesFileExist (cacheFile index)
1204+ if exists
1205+ then structuredDecodeFileOrFail (cacheFile index)
1206+ else updatePackageIndexCacheFile verbosity index >> readNoIndexCache' verbosity index
11991207
12001208-- | Write the 'Index' cache to the filesystem
12011209writeIndexCache :: Index -> Cache -> IO ()
0 commit comments