forked from TrueCloudLab/restic
Honor RESTIC_CACHE_DIR environment variable
Fix #3382: restic check doesn't obey the RESTIC_CACHE_DIR environment variable
This commit is contained in:
parent
553ea36ca6
commit
95eb859b54
2 changed files with 10 additions and 1 deletions
|
@ -9,6 +9,7 @@ import (
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
"github.com/restic/restic/internal/cache"
|
||||||
"github.com/restic/restic/internal/checker"
|
"github.com/restic/restic/internal/checker"
|
||||||
"github.com/restic/restic/internal/errors"
|
"github.com/restic/restic/internal/errors"
|
||||||
"github.com/restic/restic/internal/fs"
|
"github.com/restic/restic/internal/fs"
|
||||||
|
@ -146,6 +147,9 @@ func prepareCheckCache(opts CheckOptions, gopts *GlobalOptions) (cleanup func())
|
||||||
}
|
}
|
||||||
|
|
||||||
cachedir := gopts.CacheDir
|
cachedir := gopts.CacheDir
|
||||||
|
if cachedir == "" {
|
||||||
|
cachedir = cache.EnvDir()
|
||||||
|
}
|
||||||
|
|
||||||
// use a cache in a temporary directory
|
// use a cache in a temporary directory
|
||||||
tempdir, err := ioutil.TempDir(cachedir, "restic-check-cache-")
|
tempdir, err := ioutil.TempDir(cachedir, "restic-check-cache-")
|
||||||
|
|
7
internal/cache/dir.go
vendored
7
internal/cache/dir.go
vendored
|
@ -6,10 +6,15 @@ import (
|
||||||
"path/filepath"
|
"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
|
// DefaultDir returns $RESTIC_CACHE_DIR, or the default cache directory
|
||||||
// for the current OS if that variable is not set.
|
// for the current OS if that variable is not set.
|
||||||
func DefaultDir() (cachedir string, err error) {
|
func DefaultDir() (cachedir string, err error) {
|
||||||
cachedir = os.Getenv("RESTIC_CACHE_DIR")
|
cachedir = EnvDir()
|
||||||
if cachedir != "" {
|
if cachedir != "" {
|
||||||
return cachedir, nil
|
return cachedir, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue