From e877c5b10c9e42f4e709b30929f55d6cb3b60524 Mon Sep 17 00:00:00 2001 From: Daniel Gröber Date: Fri, 16 Sep 2016 00:09:31 +0200 Subject: Use $XDG_CACHE_HOME instead of '.ghc-mod' (Fix DanielG/ghc-mod#833) --- CabalHelper/Shared/Common.hs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'CabalHelper/Shared') 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" -- cgit v1.2.3