Commit 2cce2cb8 authored by Edsko de Vries's avatar Edsko de Vries
Browse files

Introduce datatype for the Cabal index cache

Right now this just wraps the list of cache entries, but this might make it
easier in the future to change the structure of the cache.
parent 99454f73
......@@ -368,7 +368,7 @@ updatePackageIndexCacheFile verbosity index = do
. maybeDecompress
=<< BS.readFile (indexFile index)
entries <- lazySequence pkgsOrPrefs
let cache = map toCache $ catMaybes entries
let cache = Cache { cacheEntries = map toCache $ catMaybes entries }
writeFile (cacheFile index) (showIndexCache cache)
where
toCache :: PackageOrDep -> IndexCacheEntry
......@@ -398,10 +398,10 @@ readPackageIndexCacheFile mkPkg index mode = do
packageIndexFromCache :: Package pkg
=> (PackageEntry -> pkg)
-> Handle
-> [IndexCacheEntry]
-> Cache
-> ReadPackageIndexMode
-> IO (PackageIndex pkg, [Dependency])
packageIndexFromCache mkPkg hnd entrs mode = accum mempty [] entrs
packageIndexFromCache mkPkg hnd Cache{..} mode = accum mempty [] cacheEntries
where
accum srcpkgs prefs [] = do
-- Have to reverse entries, since in a tar file, later entries mask
......@@ -551,8 +551,15 @@ showIndexCacheEntry entry = unwords $ case entry of
, display dep
]
readIndexCache :: BSS.ByteString -> [IndexCacheEntry]
readIndexCache = mapMaybe readIndexCacheEntry . BSS.lines
-- | Cabal caches various information about the Hackage index
data Cache = Cache {
cacheEntries :: [IndexCacheEntry]
}
readIndexCache :: BSS.ByteString -> Cache
readIndexCache bs = Cache {
cacheEntries = mapMaybe readIndexCacheEntry $ BSS.lines bs
}
showIndexCache :: [IndexCacheEntry] -> String
showIndexCache = unlines . map showIndexCacheEntry
showIndexCache :: Cache -> String
showIndexCache Cache{..} = unlines $ map showIndexCacheEntry cacheEntries
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment