mirror of
https://github.com/octoleo/restic.git
synced 2024-11-26 14:56:29 +00:00
Test if a config file on open
This commit is contained in:
parent
90ba606633
commit
d0db1bf9b3
@ -402,6 +402,16 @@ func open(s string, opts options.Options) (restic.Backend, error) {
|
||||
return nil, errors.Fatalf("unable to open repo at %v: %v", s, err)
|
||||
}
|
||||
|
||||
// check if config is there
|
||||
fi, err := be.Stat(restic.Handle{Type: restic.ConfigFile})
|
||||
if err != nil {
|
||||
return nil, errors.Fatalf("unable to open config file: %v\nIs there a repository at the following location?\n%v", err, s)
|
||||
}
|
||||
|
||||
if fi.Size == 0 {
|
||||
return nil, errors.New("config file has zero size, invalid repository?")
|
||||
}
|
||||
|
||||
return be, nil
|
||||
}
|
||||
|
||||
|
@ -34,13 +34,6 @@ func Open(cfg Config) (*Local, error) {
|
||||
|
||||
be := &Local{Config: cfg, Layout: l}
|
||||
|
||||
// test if all necessary dirs are there
|
||||
for _, d := range be.Paths() {
|
||||
if _, err := fs.Stat(d); err != nil {
|
||||
return nil, errors.Wrap(err, "Open")
|
||||
}
|
||||
}
|
||||
|
||||
return be, nil
|
||||
}
|
||||
|
||||
@ -65,7 +58,7 @@ func Create(cfg Config) (*Local, error) {
|
||||
return nil, errors.New("config file already exists")
|
||||
}
|
||||
|
||||
// create paths for data, refs and temp
|
||||
// create paths for data and refs
|
||||
for _, d := range be.Paths() {
|
||||
err := fs.MkdirAll(d, backend.Modes.Dir)
|
||||
if err != nil {
|
||||
|
@ -124,13 +124,6 @@ func Open(cfg Config) (*SFTP, error) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// test if all necessary dirs and files are there
|
||||
for _, d := range sftp.Paths() {
|
||||
if _, err := sftp.c.Lstat(d); err != nil {
|
||||
return nil, errors.Errorf("%s does not exist", d)
|
||||
}
|
||||
}
|
||||
|
||||
debug.Log("layout: %v\n", sftp.Layout)
|
||||
|
||||
sftp.Config = cfg
|
||||
@ -204,7 +197,7 @@ func Create(cfg Config) (*SFTP, error) {
|
||||
return nil, errors.New("config file already exists")
|
||||
}
|
||||
|
||||
// create paths for data, refs and temp blobs
|
||||
// create paths for data and refs
|
||||
for _, d := range sftp.Paths() {
|
||||
err = sftp.mkdirAll(d, backend.Modes.Dir)
|
||||
debug.Log("mkdirAll %v -> %v", d, err)
|
||||
|
Loading…
Reference in New Issue
Block a user