on master help sign in
Use remote-repo-cache (#51)
863be9bMichael Snoyman
Stackage/Util.hs+11−1
@@ -4,8 +4,10 @@ module Stackage.Util where
4import qualified Codec.Archive.Tar as Tar
4import qualified Codec.Archive.Tar as Tar
5import qualified Codec.Archive.Tar.Entry as TarEntry
5import qualified Codec.Archive.Tar.Entry as TarEntry
6import Control.Monad (guard, when)
6import Control.Monad (guard, when)
7+import Data.Char (isSpace)
7import Data.List (stripPrefix)
8import Data.List (stripPrefix)
8import qualified Data.Map as Map
9import qualified Data.Map as Map
10+import Data.Maybe (mapMaybe)
9import qualified Data.Set as Set
11import qualified Data.Set as Set
10import Data.Version (showVersion)
12import Data.Version (showVersion)
11import Distribution.License (License (..))
13import Distribution.License (License (..))
@@ -56,7 +58,15 @@ getCabalRoot = getAppUserDataDirectory "cabal"
56getTarballName :: IO FilePath
58getTarballName :: IO FilePath
57getTarballName = do
59getTarballName = do
58 c <- getCabalRoot
60 c <- getCabalRoot
61+ configLines <- fmap lines $ readFile (c </> "config")
62+ case mapMaybe getRemoteCache configLines of
59− return $ c </> "packages" </> "hackage.haskell.org" </> "00-index.tar"
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
60
70
61stableRepoName, extraRepoName :: String
71stableRepoName, extraRepoName :: String
62stableRepoName = "stackage"
72stableRepoName = "stackage"