Merge pull request #927 from restic/open-check-config

Test if a config file on open
This commit is contained in:
Alexander Neumann 2017-04-19 19:29:27 +02:00
commit aed0126102
3 changed files with 12 additions and 16 deletions

View File

@ -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) 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 return be, nil
} }

View File

@ -34,13 +34,6 @@ func Open(cfg Config) (*Local, error) {
be := &Local{Config: cfg, Layout: l} 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 return be, nil
} }
@ -65,7 +58,7 @@ func Create(cfg Config) (*Local, error) {
return nil, errors.New("config file already exists") 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() { for _, d := range be.Paths() {
err := fs.MkdirAll(d, backend.Modes.Dir) err := fs.MkdirAll(d, backend.Modes.Dir)
if err != nil { if err != nil {

View File

@ -124,13 +124,6 @@ func Open(cfg Config) (*SFTP, error) {
return nil, err 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) debug.Log("layout: %v\n", sftp.Layout)
sftp.Config = cfg sftp.Config = cfg
@ -204,7 +197,7 @@ func Create(cfg Config) (*SFTP, error) {
return nil, errors.New("config file already exists") 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() { for _, d := range sftp.Paths() {
err = sftp.mkdirAll(d, backend.Modes.Dir) err = sftp.mkdirAll(d, backend.Modes.Dir)
debug.Log("mkdirAll %v -> %v", d, err) debug.Log("mkdirAll %v -> %v", d, err)