aboutsummaryrefslogtreecommitdiff
path: root/CabalHelper/Shared
diff options
context:
space:
mode:
authorDaniel Gröber <dxld@darkboxed.org>2016-09-16 00:09:31 +0200
committerDaniel Gröber <dxld@darkboxed.org>2017-09-18 01:41:49 +0200
commite877c5b10c9e42f4e709b30929f55d6cb3b60524 (patch)
treefac73fbaf3e691c8134ba4406e93839807ab52bb /CabalHelper/Shared
parent2a2c305c395cffbee8bfa84fdc372466a0ea257f (diff)
Use $XDG_CACHE_HOME instead of '.ghc-mod' (Fix DanielG/ghc-mod#833)
Diffstat (limited to 'CabalHelper/Shared')
-rw-r--r--CabalHelper/Shared/Common.hs16
1 files changed, 14 insertions, 2 deletions
diff --git a/CabalHelper/Shared/Common.hs b/CabalHelper/Shared/Common.hs
index 3d79f90..588cd03 100644
--- a/CabalHelper/Shared/Common.hs
+++ b/CabalHelper/Shared/Common.hs
@@ -29,6 +29,7 @@ import qualified Data.ByteString as BS
import qualified Data.ByteString.Char8 as BS8
import System.Environment
import System.IO
+import qualified System.Info
import System.Exit
import System.Directory
import System.FilePath
@@ -84,8 +85,19 @@ runReadP p i = case filter ((=="") . snd) $ readP_to_S p i of
(a,""):[] -> a
_ -> error $ "Error parsing: " ++ show i
-appDataDir :: IO FilePath
-appDataDir = (</> "cabal-helper") <$> getAppUserDataDirectory "ghc-mod"
+appCacheDir :: IO FilePath
+appCacheDir =
+ (</> "ghc-mod") <$> getEnvDefault "XDG_CACHE_HOME" (homeRel cache)
+ where
+ getEnvDefault var def = lookupEnv var >>= \m -> case m of Nothing -> def; Just x -> return x
+ homeRel path = (</> path) <$> getHomeDirectory
+ cache =
+ case System.Info.os of
+ "mingw32" -> windowsCache
+ _ -> unixCache
+
+ windowsCache = "Local Settings" </> "Cache"
+ unixCache = ".cache"
isCabalFile :: FilePath -> Bool
isCabalFile f = takeExtension' f == ".cabal"