2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-30 22:33:30 +00:00

Merge pull request #287 from restic/fix-279

Remove tests for directories
This commit is contained in:
Alexander Neumann 2015-08-27 22:07:07 +02:00
commit f653aca0ed
3 changed files with 9 additions and 20 deletions

View File

@ -57,18 +57,11 @@ func Create(dir string) (*Local, error) {
}
// test if config file already exists
_, err := os.Lstat(backend.Paths.Config)
_, err := os.Lstat(filepath.Join(dir, backend.Paths.Config))
if err == nil {
return nil, errors.New("config file already exists")
}
// test if directories already exist
for _, d := range dirs[1:] {
if _, err := os.Stat(d); err == nil {
return nil, fmt.Errorf("dir %s already exists", d)
}
}
// create paths for data, refs and temp
for _, d := range dirs {
err := os.MkdirAll(d, backend.Modes.Dir)

View File

@ -5,6 +5,7 @@ import (
"io/ioutil"
"testing"
"github.com/restic/restic/backend"
"github.com/restic/restic/backend/local"
. "github.com/restic/restic/test"
)
@ -46,11 +47,13 @@ func TestLocalBackendCreationFailures(t *testing.T) {
b := setupLocalBackend(t)
defer teardownLocalBackend(t, b)
// create a fake config file
blob, err := b.Create()
OK(t, err)
fmt.Fprintf(blob, "config\n")
OK(t, blob.Finalize(backend.Config, ""))
// test failure to create a new repository at the same location
b2, err := local.Create(b.Location())
Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
// test failure to create a new repository at the same location without a config file
b2, err = local.Create(b.Location())
Assert(t, err != nil && b2 == nil, fmt.Sprintf("creating a repository at %s for the second time should have failed", b.Location()))
}

View File

@ -110,18 +110,11 @@ func Create(dir string, program string, args ...string) (*SFTP, error) {
}
// test if config file already exists
_, err = sftp.c.Lstat(backend.Paths.Config)
_, err = sftp.c.Lstat(filepath.Join(dir, backend.Paths.Config))
if err == nil {
return nil, errors.New("config file already exists")
}
// test if directories already exist
for _, d := range dirs[1:] {
if _, err := sftp.c.Lstat(d); err == nil {
return nil, fmt.Errorf("dir %s already exists", d)
}
}
// create paths for data, refs and temp blobs
for _, d := range dirs {
err = sftp.mkdirAll(d, backend.Modes.Dir)