@@ -4,8 +4,10 @@ module Stackage.Util where
44import qualified Codec.Archive.Tar as Tar
55import qualified Codec.Archive.Tar.Entry as TarEntry
66import Control.Monad (guard, when)
7+import Data.Char (isSpace)
78import Data.List (stripPrefix)
89import qualified Data.Map as Map
10+import Data.Maybe (mapMaybe)
911import qualified Data.Set as Set
1012import Data.Version (showVersion)
1113import Distribution.License (License (..))
@@ -56,7 +58,15 @@ getCabalRoot = getAppUserDataDirectory "cabal"
5658getTarballName :: IO FilePath
5759getTarballName = do
5860 c <- getCabalRoot
59− return $ c </> "packages" </> "hackage.haskell.org" </> "00-index.tar"
61+ configLines <- fmap lines $ readFile (c </> "config")
62+ case mapMaybe getRemoteCache configLines of
63+ [x] -> return $ x </> "hackage.haskell.org" </> "00-index.tar"
64+ [] -> error $ "No remote-repo-cache found in Cabal config file"
65+ _ -> error $ "Multiple remote-repo-cache entries found in Cabal config file"
66+ where
67+ getRemoteCache s = do
68+ ("remote-repo-cache", ':':v) <- Just $ break (== ':') s
69+ Just $ reverse $ dropWhile isSpace $ reverse $ dropWhile isSpace v
6070
6171stableRepoName, extraRepoName :: String
6272stableRepoName = "stackage"