aboutsummaryrefslogtreecommitdiffhomepage
path: root/main_test.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2023-07-27 20:59:47 +0200
committerGitHub <[email protected]>2023-07-27 20:59:47 +0200
commitb3f10556f0ab8a92bdd92e25c67685947317d188 (patch)
tree61faa97a403aec86207bd50d8aa9b815dc3aa579 /main_test.go
parent4d7af757c99a561744c87c477d10b89e5c9d7e35 (diff)
downloadhugo-b3f10556f0ab8a92bdd92e25c67685947317d188.tar.gz
hugo-b3f10556f0ab8a92bdd92e25c67685947317d188.zip
Use os.UserCacheDir as first fallback if cacheDir is not set
We will now try 1. cacheDir (or, commonly set in environment as `HUGO_CACHEDIR`) 2. if on Netlify we use `/opt/build/cache/hugo_cache/` 3. os.UserCacheDir 4. A temp dir Storing the cache, especially the module cache, in a temporary idea has had lots of hard to debug issues, especially on MacOS, which this commit tries to fix. This should also make it easier to locate the Hugo cache: >UserCacheDir returns the default root directory to use for user-specific cached data. Users should create their own application-specific subdirectory within this one and use that. > >On Unix systems, it returns $XDG_CACHE_HOME as specified by https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html if non-empty, else $HOME/.cache. On Darwin, it returns $HOME/Library/Caches. On Windows, it returns %LocalAppData%. On Plan 9, it returns $home/lib/cache. > >If the location cannot be determined (for example, $HOME is not defined), then it will return an error. Fixes #11286 Fixes #11291
Diffstat (limited to 'main_test.go')
-rw-r--r--main_test.go19
1 files changed, 17 insertions, 2 deletions
diff --git a/main_test.go b/main_test.go
index 6274cd9bb..c5a59828f 100644
--- a/main_test.go
+++ b/main_test.go
@@ -375,8 +375,23 @@ func testSetupFunc() func(env *testscript.Env) error {
return func(env *testscript.Env) error {
var keyVals []string
keyVals = append(keyVals, "HUGO_TESTRUN", "true")
- hugoCachedDir := filepath.Join(env.WorkDir, "hugocache")
- keyVals = append(keyVals, "HUGO_CACHEDIR", hugoCachedDir)
+ keyVals = append(keyVals, "HUGO_CACHEDIR", filepath.Join(env.WorkDir, "hugocache"))
+ xdghome := filepath.Join(env.WorkDir, "xdgcachehome")
+ keyVals = append(keyVals, "XDG_CACHE_HOME", xdghome)
+ home := filepath.Join(env.WorkDir, "home")
+ keyVals = append(keyVals, "HOME", home)
+
+ if runtime.GOOS == "darwin" {
+ if err := os.MkdirAll(filepath.Join(home, "Library", "Caches"), 0777); err != nil {
+ return err
+ }
+ }
+
+ if runtime.GOOS == "linux" {
+ if err := os.MkdirAll(xdghome, 0777); err != nil {
+ return err
+ }
+ }
keyVals = append(keyVals, "SOURCE", sourceDir)