mirror of
https://github.com/restic/restic.git
synced 2025-12-03 20:51:47 +00:00
cache: Print message when new cache is created
Sometimes, users run restic without retaining the local cache directories. This was reported several times in the past. Restic will now print a message whenever a new cache directory is created from scratch (i.e. it did not exist before), so users have a chance to recognize when the cache is not kept between different runs of restic.
This commit is contained in:
16
internal/cache/dir.go
vendored
16
internal/cache/dir.go
vendored
@@ -68,25 +68,31 @@ func DefaultDir() (cachedir string, err error) {
|
||||
return cachedir, nil
|
||||
}
|
||||
|
||||
func mkdirCacheDir(cachedir string) error {
|
||||
// mkdirCacheDir ensures that the cache directory exists. It it didn't, created
|
||||
// is set to true.
|
||||
func mkdirCacheDir(cachedir string) (created bool, err error) {
|
||||
var newCacheDir bool
|
||||
|
||||
fi, err := fs.Stat(cachedir)
|
||||
if os.IsNotExist(errors.Cause(err)) {
|
||||
err = fs.MkdirAll(cachedir, 0700)
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "MkdirAll")
|
||||
return true, errors.Wrap(err, "MkdirAll")
|
||||
}
|
||||
|
||||
fi, err = fs.Stat(cachedir)
|
||||
debug.Log("create cache dir %v", cachedir)
|
||||
|
||||
newCacheDir = true
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrap(err, "Stat")
|
||||
return newCacheDir, errors.Wrap(err, "Stat")
|
||||
}
|
||||
|
||||
if !fi.IsDir() {
|
||||
return errors.Errorf("cache dir %v is not a directory", cachedir)
|
||||
return newCacheDir, errors.Errorf("cache dir %v is not a directory", cachedir)
|
||||
}
|
||||
|
||||
return nil
|
||||
return newCacheDir, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user