]> git.maquefel.me Git - brevno-suite/hugo/commitdiff
testing: Write test caches to /tmp
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 4 Aug 2023 09:41:59 +0000 (11:41 +0200)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Fri, 4 Aug 2023 16:46:43 +0000 (18:46 +0200)
Fixes #11327

helpers/path.go

index 57877bfedc5b061bef03404965ceb2b110ec790a..3172d345249044f15fa8467f600df2ea0e1a9531 100644 (file)
@@ -27,6 +27,7 @@ import (
 
        "github.com/gohugoio/hugo/common/herrors"
        "github.com/gohugoio/hugo/common/text"
+       "github.com/gohugoio/hugo/htesting"
 
        "github.com/gohugoio/hugo/hugofs"
 
@@ -411,11 +412,14 @@ func GetCacheDir(fs afero.Fs, cacheDir string) (string, error) {
 
        const hugoCacheBase = "hugo_cache"
 
-       userCacheDir, err := os.UserCacheDir()
-       if err == nil {
-               cacheDir := filepath.Join(userCacheDir, hugoCacheBase)
-               if err := fs.Mkdir(cacheDir, 0777); err == nil || os.IsExist(err) {
-                       return cacheDir, nil
+       // Avoid filling up the home dir with Hugo cache dirs from development.
+       if !htesting.IsTest {
+               userCacheDir, err := os.UserCacheDir()
+               if err == nil {
+                       cacheDir := filepath.Join(userCacheDir, hugoCacheBase)
+                       if err := fs.Mkdir(cacheDir, 0777); err == nil || os.IsExist(err) {
+                               return cacheDir, nil
+                       }
                }
        }