mirror of
https://github.com/octoleo/restic.git
synced 2024-12-22 19:08:55 +00:00
local: Create directories below data/ if it exists
This commit is contained in:
parent
ea017a49c3
commit
3686b1ffe5
@ -25,6 +25,25 @@ var _ restic.Backend = &Local{}
|
|||||||
|
|
||||||
const defaultLayout = "default"
|
const defaultLayout = "default"
|
||||||
|
|
||||||
|
// dirExists returns true if the name exists and is a directory.
|
||||||
|
func dirExists(name string) bool {
|
||||||
|
f, err := fs.Open(name)
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
fi, err := f.Stat()
|
||||||
|
if err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
if err = f.Close(); err != nil {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
return fi.IsDir()
|
||||||
|
}
|
||||||
|
|
||||||
// Open opens the local backend as specified by config.
|
// Open opens the local backend as specified by config.
|
||||||
func Open(cfg Config) (*Local, error) {
|
func Open(cfg Config) (*Local, error) {
|
||||||
debug.Log("open local backend at %v (layout %q)", cfg.Path, cfg.Layout)
|
debug.Log("open local backend at %v (layout %q)", cfg.Path, cfg.Layout)
|
||||||
@ -36,12 +55,19 @@ func Open(cfg Config) (*Local, error) {
|
|||||||
be := &Local{Config: cfg, Layout: l}
|
be := &Local{Config: cfg, Layout: l}
|
||||||
|
|
||||||
// if data dir exists, make sure that all subdirs also exist
|
// if data dir exists, make sure that all subdirs also exist
|
||||||
|
datadir := be.Dirname(restic.Handle{Type: restic.DataFile})
|
||||||
|
if dirExists(datadir) {
|
||||||
for _, d := range be.Paths() {
|
for _, d := range be.Paths() {
|
||||||
|
if _, err := filepath.Rel(datadir, d); err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
err := fs.MkdirAll(d, backend.Modes.Dir)
|
err := fs.MkdirAll(d, backend.Modes.Dir)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrap(err, "MkdirAll")
|
return nil, errors.Wrap(err, "MkdirAll")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return be, nil
|
return be, nil
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user