Skip to content

Commit 9c1624e

Browse files
committed
Move towards using XDG directories.
1 parent 4f8aeb2 commit 9c1624e

File tree

3 files changed

+18
-29
lines changed

3 files changed

+18
-29
lines changed

Cabal-tests/tests/HackageTests.hs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ import Data.Foldable (traverse_)
2020
import Data.List (isPrefixOf, isSuffixOf)
2121
import Data.Maybe (mapMaybe)
2222
import Data.Monoid (Sum (..))
23+
import Distribution.Client.Config (getConfigFilePath)
2324
import Distribution.PackageDescription.Check (PackageCheck (..), checkPackage)
2425
import Distribution.PackageDescription.PrettyPrint (showGenericPackageDescription)
2526
import Distribution.PackageDescription.Quirks (patchQuirks)
2627
import Distribution.Simple.Utils (fromUTF8BS, toUTF8BS)
2728
import Numeric (showFFloat)
28-
import System.Directory (getAppUserDataDirectory)
29+
import System.Directory (getXdgDirectory, XdgDirectory(XdgData))
2930
import System.Environment (lookupEnv)
3031
import System.Exit (exitFailure)
3132
import System.FilePath ((</>))
@@ -63,23 +64,15 @@ import Data.TreeDiff.Pretty (ansiWlEditExprCompact)
6364
parseIndex :: (Monoid a, NFData a) => (FilePath -> Bool)
6465
-> (FilePath -> B.ByteString -> IO a) -> IO a
6566
parseIndex predicate action = do
66-
cabalDir <- getAppUserDataDirectory "cabal"
67-
configPath <- getCabalConfigPath cabalDir
67+
configPath <- getConfigFilePath
6868
cfg <- B.readFile configPath
6969
cfgFields <- either (fail . show) pure $ Parsec.readFields cfg
70+
repoCache <- case lookupInConfig "remote-repo-cache" cfgFields of
71+
[] -> defaultCacheDir -- Default
72+
(rrc : _) -> return rrc -- User-specified
7073
let repos = reposFromConfig cfgFields
71-
repoCache = case lookupInConfig "remote-repo-cache" cfgFields of
72-
[] -> cabalDir </> "packages" -- Default
73-
(rrc : _) -> rrc -- User-specified
7474
tarName repo = repoCache </> repo </> "01-index.tar"
7575
mconcat <$> traverse (parseIndex' predicate action . tarName) repos
76-
where
77-
getCabalConfigPath cabalDir = do
78-
mx <- lookupEnv "CABAL_CONFIG"
79-
case mx of
80-
Just x -> return x
81-
Nothing -> return (cabalDir </> "config")
82-
8376

8477
parseIndex'
8578
:: (Monoid a, NFData a)

cabal-install/src/Distribution/Client/Config.hs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ import Text.PrettyPrint
130130
import Text.PrettyPrint.HughesPJ
131131
( text, Doc )
132132
import System.Directory
133-
( createDirectoryIfMissing, getAppUserDataDirectory, renameFile )
133+
( createDirectoryIfMissing, getAppUserDataDirectory, getXdgDirectory, XdgDirectory(XdgCache, XdgConfig), renameFile )
134134
import Network.URI
135135
( URI(..), URIAuth(..), parseURI )
136136
import System.FilePath
@@ -595,25 +595,21 @@ getCabalDir = do
595595
Just dir -> return dir
596596

597597
defaultConfigFile :: IO FilePath
598-
defaultConfigFile = do
599-
dir <- getCabalDir
600-
return $ dir </> "config"
598+
defaultConfigFile =
599+
getXdgDirectory XdgConfig $ "cabal" </> "config"
601600

602601
defaultCacheDir :: IO FilePath
603-
defaultCacheDir = do
604-
dir <- getCabalDir
605-
return $ dir </> "packages"
602+
defaultCacheDir =
603+
getXdgDirectory XdgCache $ "cabal" </> "packages"
606604

607605
defaultLogsDir :: IO FilePath
608-
defaultLogsDir = do
609-
dir <- getCabalDir
610-
return $ dir </> "logs"
606+
defaultLogsDir =
607+
getXdgDirectory XdgCache $ "cabal" </> "logs"
611608

612609
-- | Default position of the world file
613610
defaultWorldFile :: IO FilePath
614-
defaultWorldFile = do
615-
dir <- getCabalDir
616-
return $ dir </> "world"
611+
defaultWorldFile =
612+
getXdgDirectory XdgCache $ "cabal" </> "world"
617613

618614
defaultExtraPath :: IO [FilePath]
619615
defaultExtraPath = do

doc/installing-packages.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ Various environment variables affect ``cabal-install``.
5151

5252
``CABAL_DIR``
5353
Default content directory for ``cabal-install`` files.
54-
Default value is ``getAppUserDataDirectory "cabal"``, which is
55-
``$HOME/.cabal`` on unix systems and ``%APPDATA%\cabal`` in Windows.
54+
Default value is ``getXdgDirectory XdgCache "cabal"``, which is
55+
``$XDG_CACHE_HOME/cabal`` on unix systems and ``%APPDATA%\cabal`` in Windows.
5656

5757
.. note::
5858

@@ -244,4 +244,4 @@ dependencies in a single step. To do this, run:
244244

245245
To browse the list of available packages, visit the `Hackage`_ web site.
246246

247-
.. _Hackage: https://hackage.haskell.org/
247+
.. _Hackage: https://hackage.haskell.org/

0 commit comments

Comments
 (0)