mirror of
https://github.com/octoleo/restic.git
synced 2024-11-05 21:07:52 +00:00
Merge pull request #1973 from restic/announce-new-cache
cache: Print message when new cache is created
This commit is contained in:
commit
16885529f7
@ -376,6 +376,10 @@ func OpenRepository(opts GlobalOptions) (*repository.Repository, error) {
|
||||
return s, nil
|
||||
}
|
||||
|
||||
if c.Created && !opts.JSON {
|
||||
Verbosef("created new cache in %v\n", c.Base)
|
||||
}
|
||||
|
||||
// start using the cache
|
||||
s.UseCache(c)
|
||||
|
||||
|
17
internal/cache/cache.go
vendored
17
internal/cache/cache.go
vendored
@ -19,6 +19,7 @@ import (
|
||||
type Cache struct {
|
||||
Path string
|
||||
Base string
|
||||
Created bool
|
||||
PerformReadahead func(restic.Handle) bool
|
||||
}
|
||||
|
||||
@ -98,7 +99,7 @@ func New(id string, basedir string) (c *Cache, err error) {
|
||||
}
|
||||
}
|
||||
|
||||
err = mkdirCacheDir(basedir)
|
||||
created, err := mkdirCacheDir(basedir)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@ -121,8 +122,13 @@ func New(id string, basedir string) (c *Cache, err error) {
|
||||
}
|
||||
|
||||
// create the repo cache dir if it does not exist yet
|
||||
if err = fs.MkdirAll(cachedir, dirMode); err != nil {
|
||||
return nil, err
|
||||
_, err = fs.Lstat(cachedir)
|
||||
if os.IsNotExist(err) {
|
||||
err = fs.MkdirAll(cachedir, dirMode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
created = true
|
||||
}
|
||||
|
||||
// update the timestamp so that we can detect old cache dirs
|
||||
@ -145,8 +151,9 @@ func New(id string, basedir string) (c *Cache, err error) {
|
||||
}
|
||||
|
||||
c = &Cache{
|
||||
Path: cachedir,
|
||||
Base: basedir,
|
||||
Path: cachedir,
|
||||
Base: basedir,
|
||||
Created: created,
|
||||
PerformReadahead: func(restic.Handle) bool {
|
||||
// do not perform readahead by default
|
||||
return false
|
||||
|
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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user