diff --git a/src/cmds/restic/global.go b/src/cmds/restic/global.go index b88a25ec8..770a222e8 100644 --- a/src/cmds/restic/global.go +++ b/src/cmds/restic/global.go @@ -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 } diff --git a/src/restic/backend/local/local.go b/src/restic/backend/local/local.go index b140fd8f8..16bf92c11 100644 --- a/src/restic/backend/local/local.go +++ b/src/restic/backend/local/local.go @@ -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 { diff --git a/src/restic/backend/sftp/sftp.go b/src/restic/backend/sftp/sftp.go index b6f71b4c3..8b30eedf4 100644 --- a/src/restic/backend/sftp/sftp.go +++ b/src/restic/backend/sftp/sftp.go @@ -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)