From 2528f7370866f22b6360631602a59367809e8e20 Mon Sep 17 00:00:00 2001 From: Javier Sagredo Date: Thu, 9 Jan 2025 11:07:17 +0100 Subject: [PATCH] Create noindex.cache if missing --- .../src/Distribution/Client/IndexUtils.hs | 18 +++++++++++++----- changelog.d/pr-10730 | 11 +++++++++++ 2 files changed, 24 insertions(+), 5 deletions(-) create mode 100644 changelog.d/pr-10730 diff --git a/cabal-install/src/Distribution/Client/IndexUtils.hs b/cabal-install/src/Distribution/Client/IndexUtils.hs index 6027f5e53f3..035adde98e0 100644 --- a/cabal-install/src/Distribution/Client/IndexUtils.hs +++ b/cabal-install/src/Distribution/Client/IndexUtils.hs @@ -1167,12 +1167,14 @@ readIndexCache verbosity index = do -- 'dieWithException's if it fails again). Throws IOException if any arise. readNoIndexCache :: Verbosity -> Index -> IO NoIndexCache readNoIndexCache verbosity index = do - cacheOrFail <- readNoIndexCache' index + cacheOrFail <- readNoIndexCache' verbosity index case cacheOrFail of Left msg -> do warn verbosity $ concat - [ "Parsing the index cache failed (" + [ "Parsing the index cache for repo \"" + , unRepoName (repoName repo) + , "\" failed (" , msg , "). " , "Trying to regenerate the index cache..." @@ -1180,10 +1182,12 @@ readNoIndexCache verbosity index = do updatePackageIndexCacheFile verbosity index - either (dieWithException verbosity . CorruptedIndexCache) return =<< readNoIndexCache' index + either (dieWithException verbosity . CorruptedIndexCache) return =<< readNoIndexCache' verbosity index -- we don't hash cons local repository cache, they are hopefully small Right res -> return res + where + RepoIndex _ctxt repo = index -- | Read the 'Index' cache from the filesystem. Throws IO exceptions -- if any arise and returns Left on invalid input. @@ -1194,8 +1198,12 @@ readIndexCache' index | otherwise = Right . read00IndexCache <$> BSS.readFile (cacheFile index) -readNoIndexCache' :: Index -> IO (Either String NoIndexCache) -readNoIndexCache' index = structuredDecodeFileOrFail (cacheFile index) +readNoIndexCache' :: Verbosity -> Index -> IO (Either String NoIndexCache) +readNoIndexCache' verbosity index = do + exists <- doesFileExist (cacheFile index) + if exists + then structuredDecodeFileOrFail (cacheFile index) + else updatePackageIndexCacheFile verbosity index >> readNoIndexCache' verbosity index -- | Write the 'Index' cache to the filesystem writeIndexCache :: Index -> Cache -> IO () diff --git a/changelog.d/pr-10730 b/changelog.d/pr-10730 new file mode 100644 index 00000000000..e313e8f2283 --- /dev/null +++ b/changelog.d/pr-10730 @@ -0,0 +1,11 @@ +synopsis: Create `noindex.cache` file if missing +packages: cabal-install +prs: #10730 +issues: #9891 +significance: + +description: { + +- Local+noindex repositories will have their `noindex.cache` file created the first time they are accessed. + +}