From 640913f8d2cff6d80dfa836efa45ba3aa4220545 Mon Sep 17 00:00:00 2001 From: Javier Neira Date: Mon, 16 Sep 2019 09:51:00 +0200 Subject: [PATCH] Fix default cache handling in windows (#1272) * Ignore all stack*.yaml.lock files * Use `$LOCALAPPDATA` environment variable in windows --- .gitignore | 2 +- dhall/src/Dhall/Import.hs | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index e2e3b2d..fb4e46f 100644 --- a/.gitignore +++ b/.gitignore @@ -22,4 +22,4 @@ cabal.project.local~ .ghc.environment.* .cache .history -stack.yaml.lock +stack*.yaml.lock diff --git a/dhall/src/Dhall/Import.hs b/dhall/src/Dhall/Import.hs index dfc2907..ece1e96 100644 --- a/dhall/src/Dhall/Import.hs +++ b/dhall/src/Dhall/Import.hs @@ -201,6 +201,7 @@ import qualified Dhall.Parser import qualified Dhall.Pretty.Internal import qualified Dhall.TypeCheck import qualified System.Environment +import qualified System.Info import qualified System.Directory as Directory import qualified System.FilePath as FilePath import qualified Text.Megaparsec @@ -792,12 +793,25 @@ getCacheDirectory = alternative₀ <|> alternative₁ Just xdgCacheHome -> return xdgCacheHome Nothing -> empty - alternative₁ = do - maybeHomeDirectory <- liftIO (System.Environment.lookupEnv "HOME") + alternative₁ + | isWindows = do + maybeLocalAppDirectory <- + liftIO (System.Environment.lookupEnv "LOCALAPPDATA") + + case maybeLocalAppDirectory of + Just localAppDirectory -> return localAppDirectory + Nothing -> empty + + | otherwise = do + maybeHomeDirectory <- + liftIO (System.Environment.lookupEnv "HOME") + + case maybeHomeDirectory of + Just homeDirectory -> return (homeDirectory ".cache") + Nothing -> empty + + where isWindows = System.Info.os == "mingw32" - case maybeHomeDirectory of - Just homeDirectory -> return (homeDirectory ".cache") - Nothing -> empty -- If the URL contains headers typecheck them and replace them with their normal -- forms.