mirror of https://github.com/restic/restic.git
Merge pull request #3474 from kitone/fix-issue-3382
Honor RESTIC_CACHE_DIR environment variable
This commit is contained in:
commit
cb81ee9396
|
@ -0,0 +1,9 @@
|
|||
Change: honor RESTIC_CACHE_DIR environment variable in the check command
|
||||
|
||||
--cache-dir option doesn't honor the RESTIC_CACHE_DIR environment variable by
|
||||
default. This fixes an issue with the restic check command that doesn't obey the
|
||||
RESTIC_CACHE_DIR environment variable. Extend the behavior of cache command to
|
||||
manage directories created by restic check.
|
||||
|
||||
https://github.com/restic/restic/issues/3382
|
||||
https://github.com/restic/restic/pull/3474
|
|
@ -5,6 +5,7 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/restic/restic/internal/cache"
|
||||
|
@ -140,8 +141,13 @@ func runCache(opts CacheOptions, gopts GlobalOptions, args []string) error {
|
|||
size = fmt.Sprintf("%11s", formatBytes(uint64(bytes)))
|
||||
}
|
||||
|
||||
name := entry.Name()
|
||||
if !strings.HasPrefix(name, "restic-check-cache-") {
|
||||
name = name[:10]
|
||||
}
|
||||
|
||||
tab.AddRow(data{
|
||||
entry.Name()[:10],
|
||||
name,
|
||||
fmt.Sprintf("%d days ago", uint(time.Since(entry.ModTime()).Hours()/24)),
|
||||
old,
|
||||
size,
|
||||
|
|
|
@ -10,6 +10,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"
|
||||
|
@ -158,6 +159,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-")
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue