backend: remove Test method

The Test method was only used in exactly one place, namely when trying
to create a new repository it was used to check whether a config file
already exists.

Use a combination of Stat() and IsNotExist() instead.
This commit is contained in:
Michael Eischer committed 2022-12-03 11:28:10 +01:00
1 parent 57d8eedb88
commit 40ac678252
24 files changed
+47 -230

No files matched your search

-19
View File
@@ -226,25 +226,6 @@ func (be *beSwift) Stat(ctx context.Context, h restic.Handle) (bi restic.FileInf
return restic.FileInfo{Size: obj.Bytes, Name: h.Name}, nil
}
// Test returns true if a blob of the given type and name exists in the backend.
func (be *beSwift) Test(ctx context.Context, h restic.Handle) (bool, error) {
objName := be.Filename(h)
be.sem.GetToken()
defer be.sem.ReleaseToken()
switch _, _, err := be.conn.Object(ctx, be.container, objName); err {
case nil:
return true, nil
case swift.ObjectNotFound:
return false, nil
default:
return false, errors.Wrap(err, "conn.Object")
}
}
// Remove removes the blob with the given name and type.
func (be *beSwift) Remove(ctx context.Context, h restic.Handle) error {
objName := be.Filename(h)
+3 -3
View File
@@ -66,12 +66,12 @@ func newSwiftTestSuite(t testing.TB) *test.Suite {
return nil, err
}
exists, err := be.Test(context.TODO(), restic.Handle{Type: restic.ConfigFile})
if err != nil {
_, err = be.Stat(context.TODO(), restic.Handle{Type: restic.ConfigFile})
if err != nil && !be.IsNotExist(err) {
return nil, err
}
if exists {
if err == nil {
return nil, errors.New("config already exists")
}