diff --git a/cmd/restic/cmd_check.go b/cmd/restic/cmd_check.go index 2b5017ead..71629dbf0 100644 --- a/cmd/restic/cmd_check.go +++ b/cmd/restic/cmd_check.go @@ -9,6 +9,7 @@ import ( "github.com/spf13/cobra" + "github.com/restic/restic/internal/cache" "github.com/restic/restic/internal/checker" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/fs" @@ -146,6 +147,9 @@ func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions) (cleanup func()) } cachedir := gopts.CacheDir + if cachedir == "" { + cachedir = cache.EnvDir() + } // use a cache in a temporary directory tempdir, err := ioutil.TempDir(cachedir, "restic-check-cache-") diff --git a/internal/cache/dir.go b/internal/cache/dir.go index 98019036a..5abdf2313 100644 --- a/internal/cache/dir.go +++ b/internal/cache/dir.go @@ -6,10 +6,15 @@ import ( "path/filepath" ) +// EnvDir return $RESTIC_CACHE_DIR env +func EnvDir() string { + return os.Getenv("RESTIC_CACHE_DIR") +} + // DefaultDir returns $RESTIC_CACHE_DIR, or the default cache directory // for the current OS if that variable is not set. func DefaultDir() (cachedir string, err error) { - cachedir = os.Getenv("RESTIC_CACHE_DIR") + cachedir = EnvDir() if cachedir != "" { return cachedir, nil }