From 41ff2895b6c1ea8564f5ff92c6ac2d8764676699 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 --- cabal-install/src/Distribution/Client/IndexUtils.hs | 12 ++++++++++-- changelog.d/pr-10730 | 11 +++++++++++ 2 files changed, 21 insertions(+), 2 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..f2a57145b3e 100644 --- a/cabal-install/src/Distribution/Client/IndexUtils.hs +++ b/cabal-install/src/Distribution/Client/IndexUtils.hs @@ -1172,7 +1172,9 @@ readNoIndexCache verbosity index = do 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..." @@ -1184,6 +1186,8 @@ readNoIndexCache verbosity index = do -- 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. @@ -1195,7 +1199,11 @@ readIndexCache' index Right . read00IndexCache <$> BSS.readFile (cacheFile index) readNoIndexCache' :: Index -> IO (Either String NoIndexCache) -readNoIndexCache' index = structuredDecodeFileOrFail (cacheFile index) +readNoIndexCache' index = do + exists <- doesFileExist (cacheFile index) + if exists + then structuredDecodeFileOrFail (cacheFile index) + else updatePackageIndexCacheFile verbosity index >> readNoIndexCache' 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. + +}