Merge pull request #3474 from kitone/fix-issue-3382

Honor RESTIC_CACHE_DIR environment variable
This commit is contained in:
MichaelEischer
2021-11-07 17:57:54 +01:00
committed by GitHub
5 changed files with 27 additions and 3 deletions

View File

@@ -167,7 +167,7 @@ func updateTimestamp(d string) error {
const MaxCacheAge = 30 * 24 * time.Hour
func validCacheDirName(s string) bool {
r := regexp.MustCompile(`^[a-fA-F0-9]{64}$`)
r := regexp.MustCompile(`^[a-fA-F0-9]{64}$|^restic-check-cache-[0-9]+$`)
return r.MatchString(s)
}

View File

@@ -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
}