Fix default cache handling in windows (#1272)

* Ignore all stack*.yaml.lock files
* Use `$LOCALAPPDATA` environment variable in windows
This commit is contained in:
Javier Neira 2019-09-16 09:51:00 +02:00 committed by GitHub
parent 17c28d4b6c
commit 640913f8d2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 6 deletions

2
.gitignore vendored
View File

@ -22,4 +22,4 @@ cabal.project.local~
.ghc.environment.* .ghc.environment.*
.cache .cache
.history .history
stack.yaml.lock stack*.yaml.lock

View File

@ -201,6 +201,7 @@ import qualified Dhall.Parser
import qualified Dhall.Pretty.Internal import qualified Dhall.Pretty.Internal
import qualified Dhall.TypeCheck import qualified Dhall.TypeCheck
import qualified System.Environment import qualified System.Environment
import qualified System.Info
import qualified System.Directory as Directory import qualified System.Directory as Directory
import qualified System.FilePath as FilePath import qualified System.FilePath as FilePath
import qualified Text.Megaparsec import qualified Text.Megaparsec
@ -792,12 +793,25 @@ getCacheDirectory = alternative₀ <|> alternative₁
Just xdgCacheHome -> return xdgCacheHome Just xdgCacheHome -> return xdgCacheHome
Nothing -> empty Nothing -> empty
alternative = do alternative
maybeHomeDirectory <- liftIO (System.Environment.lookupEnv "HOME") | 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 -- If the URL contains headers typecheck them and replace them with their normal
-- forms. -- forms.