mirror of
https://github.com/restic/restic.git
synced 2025-10-09 07:33:53 +00:00
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:
@@ -52,23 +52,6 @@ func New() *MemoryBackend {
|
||||
return be
|
||||
}
|
||||
|
||||
// Test returns whether a file exists.
|
||||
func (be *MemoryBackend) Test(ctx context.Context, h restic.Handle) (bool, error) {
|
||||
be.sem.GetToken()
|
||||
defer be.sem.ReleaseToken()
|
||||
|
||||
be.m.Lock()
|
||||
defer be.m.Unlock()
|
||||
|
||||
debug.Log("Test %v", h)
|
||||
|
||||
if _, ok := be.data[h]; ok {
|
||||
return true, ctx.Err()
|
||||
}
|
||||
|
||||
return false, ctx.Err()
|
||||
}
|
||||
|
||||
// IsNotExist returns true if the file does not exist.
|
||||
func (be *MemoryBackend) IsNotExist(err error) bool {
|
||||
return errors.Is(err, errNotFound)
|
||||
|
@@ -26,12 +26,12 @@ func newTestSuite() *test.Suite {
|
||||
Create: func(cfg interface{}) (restic.Backend, error) {
|
||||
c := cfg.(*memConfig)
|
||||
if c.be != nil {
|
||||
ok, err := c.be.Test(context.TODO(), restic.Handle{Type: restic.ConfigFile})
|
||||
if err != nil {
|
||||
_, err := c.be.Stat(context.TODO(), restic.Handle{Type: restic.ConfigFile})
|
||||
if err != nil && !c.be.IsNotExist(err) {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if ok {
|
||||
if err == nil {
|
||||
return nil, errors.New("config already exists")
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user