Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify getGlobalCacheDir, change Windows default #384

Merged
merged 3 commits into from
Aug 23, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Bugfixes:
- Do not compile files twice when using `--watch` and Vim (#346)
- fix Dhall syntax error in packages.dhall template
- Use `git clone` instead of `git fetch` when fetching a package (#373)
- Fixes Windows global cache location; now uses `LocalAppData` as default (#384, #380)

## [0.9.0] - 2019-07-30

Expand Down
2 changes: 1 addition & 1 deletion package.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ library:
- fsnotify
- Glob
- stm
- directory
- directory >= 1.3.4.0
- mtl
- exceptions
- unliftio
Expand Down
42 changes: 6 additions & 36 deletions src/Spago/GlobalCache.hs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,10 @@ import qualified Data.ByteString as BS
import qualified Data.Map.Strict as Map
import qualified Data.Text as Text
import qualified Network.HTTP.Simple as Http
import qualified System.Environment
import qualified System.FilePath as FilePath
import qualified Turtle
import UnliftIO.Directory (XdgDirectory(XdgCache), getXdgDirectory)

import qualified Spago.Messages as Messages
import Spago.Types


Expand Down Expand Up @@ -139,43 +138,14 @@ getMetadata cacheFlag = do


-- | Directory in which spago will put its global cache
-- Code from: https://github.com/dhall-lang/dhall-haskell/blob/d8f2787745bb9567a4542973f15e807323de4a1a/dhall/src/Dhall/Import.hs#L578
--
-- In order we try to get:
-- - the folder pointed by `$XDG_CACHE_HOME`
-- - the folder pointed by `$HOME/.cache`
-- - the project-local `.cache`
-- `getXdgDirectory XdgCache` tries to find the folder pointed by
-- `$XDG_CACHE_HOME`, otherwise it uses:
-- - (on Linux/MacOS) the folder pointed by `$HOME/.cache`, or
-- - (on Windows) the folder pointed by `LocalAppData`
getGlobalCacheDir :: Spago m => m FilePath.FilePath
getGlobalCacheDir = do
echoDebug "Running `getGlobalCacheDir`"
cacheDir <- alternative₀ <|> alternative₁ <|> alternative₂ <|> alternative₃ <|> err
pure $ cacheDir </> "spago"
where
err = die Messages.cannotGetGlobalCacheDir

alternative₀ = do
maybeXDGCacheHome <- do
liftIO (System.Environment.lookupEnv "XDG_CACHE_HOME")

case maybeXDGCacheHome of
Just xdgCacheHome -> return xdgCacheHome
Nothing -> empty

alternative₁ = do
maybeHomeDirectory <- liftIO (System.Environment.lookupEnv "HOME")

case maybeHomeDirectory of
Just homeDirectory -> return (homeDirectory </> ".cache")
Nothing -> empty

alternative₂ = do
maybeWindowsHomeDirectory <- liftIO (System.Environment.lookupEnv "HomePath")

case maybeWindowsHomeDirectory of
Just homeDirectory -> return (homeDirectory </> ".cache")
Nothing -> empty

alternative₃ = pure ".spago-global-cache"
getXdgDirectory XdgCache "spago" <|> pure ".spago-global-cache"


-- | Fetch the tarball at `archiveUrl` and unpack it into `destination`
Expand Down
10 changes: 0 additions & 10 deletions src/Spago/Messages.hs
Original file line number Diff line number Diff line change
Expand Up @@ -68,16 +68,6 @@ cannotFindPackagesButItsFine = makeMessage
[ "WARNING: did not find a " <> surroundQuote "packages.dhall" <> " in your current location, skipping compiler version check"
]

cannotGetGlobalCacheDir :: Text
cannotGetGlobalCacheDir = makeMessage
[ "ERROR: Spago was not able to get a directory for the global cache. To fix this there are some things you could do:"
, ""
, "- Set either the `HOME` or `XDG_CACHE_HOME` environment variable. Depending on your OS you'll have to type a different thing in your terminal to do it:"
, " On Windows: set XDG_CACHE_DIR=\"C:\\tmp\\spago\""
, " On Linux/Mac: export XDG_CACHE_HOME='/tmp/spago'"
, ""
, "- Disable the global cache entirely, by passing to Spago `--global-cache skip`"
]

foundExistingProject :: Text -> Text
foundExistingProject pathText = makeMessage
Expand Down
1 change: 1 addition & 0 deletions stack.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ extra-deps:
- th-lift-0.8.0.1@sha256:cceb81b12c0580e02a7a3898b6d60cca5e1be080741f69ddde4f12210d8ba7ca,1960
- th-lift-instances-0.1.13@sha256:2852e468511805cb25d9e3923c9e91647d008ab4a764ec0921e5e40ff8a8e874,2625
- semver-range-0.2.8
- directory-1.3.4.0@sha256:500019f04494324d1df16cf83eefeb3f809b2b20b32a32ccd755ee0439c18bfd
stkb marked this conversation as resolved.
Show resolved Hide resolved
nix:
packages: [zlib]