From 54e1ed2972f47895d505c166e43be714a8ee813f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20D=C4=85bek?= <sznurek@gmail.com> Date: Thu, 17 Sep 2015 11:35:48 +0200 Subject: [PATCH] Made parsePackageIndex and updatePackageIndexCacheFile streaming. The parsePackageIndex wasn't streaming because resulting list was hidden in two constructors: Either and tuple. By removing that error semantics changed in updatePackageIndexCacheFile. The updatePackageIndexCacheFile problem was sequence call that evaluated whole list made by parsePackageIndex. By using lazySequence any error during index file parsing will be raised during writing to cache file. Also removed reacPackageIndexFile, as it wasn't used anywhere as far as I can tell. If this is a mistake I'll include it again. --- .../Distribution/Client/IndexUtils.hs | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/cabal-install/Distribution/Client/IndexUtils.hs b/cabal-install/Distribution/Client/IndexUtils.hs index 8743da9ac1..7364988772 100644 --- a/cabal-install/Distribution/Client/IndexUtils.hs +++ b/cabal-install/Distribution/Client/IndexUtils.hs @@ -288,33 +288,6 @@ packageDesc :: PackageEntry -> GenericPackageDescription packageDesc (NormalPackage _ descr _ _) = descr packageDesc (BuildTreeRef _ _ descr _ _) = descr --- | Read a compressed \"00-index.tar.gz\" file into a 'PackageIndex'. --- --- This is supposed to be an \"all in one\" way to easily get at the info in --- the Hackage package index. --- --- It takes a function to map a 'GenericPackageDescription' into any more --- specific instance of 'Package' that you might want to use. In the simple --- case you can just use @\_ p -> p@ here. --- - -{- -readPackageIndexFile :: Package pkg - => (PackageEntry -> pkg) - -> FilePath - -> IO (PackageIndex pkg, [Dependency]) -readPackageIndexFile mkPkg indexFile = do - (mkPkgs, prefs) <- either fail return - . parsePackageIndex - . maybeDecompress - =<< BS.readFile indexFile - - pkgEntries <- sequence mkPkgs - pkgs <- evaluate $ PackageIndex.fromList (map mkPkg pkgEntries) - return (pkgs, prefs) - --} - -- | Parse an uncompressed \"00-index.tar\" repository index file represented -- as a 'ByteString'. -- @@ -413,15 +386,13 @@ updatePackageIndexCacheFile verbosity indexFile cacheFile = do . maybeDecompress =<< BS.readFile indexFile entries <- lazySequence pkgsOrPrefs - let cache = mkCache entries + let cache = map toCache entries writeFile cacheFile (showIndexCache cache) where toCache (Pkg (NormalPackage pkgid _ _ blockNo)) = CachePackageId pkgid blockNo toCache (Pkg (BuildTreeRef refType _ _ _ blockNo)) = CacheBuildTreeRef refType blockNo toCache (Dep d) = CachePreference d - mkCache = map toCache - data ReadPackageIndexMode = ReadPackageIndexStrict | ReadPackageIndexLazyIO -- GitLab