mirror of
https://github.com/octoleo/restic.git
synced 2025-01-24 15:48:25 +00:00
commit
223da7344e
@ -8,7 +8,6 @@ import (
|
|||||||
"hash"
|
"hash"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
|
||||||
"path"
|
"path"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
@ -130,7 +129,8 @@ func (be *Backend) SetListMaxItems(i int) {
|
|||||||
// IsNotExist returns true if the error is caused by a not existing file.
|
// IsNotExist returns true if the error is caused by a not existing file.
|
||||||
func (be *Backend) IsNotExist(err error) bool {
|
func (be *Backend) IsNotExist(err error) bool {
|
||||||
debug.Log("IsNotExist(%T, %#v)", err, err)
|
debug.Log("IsNotExist(%T, %#v)", err, err)
|
||||||
return os.IsNotExist(err)
|
var aerr storage.AzureStorageServiceError
|
||||||
|
return errors.As(err, &aerr) && aerr.StatusCode == http.StatusNotFound
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join combines path components with slashes.
|
// Join combines path components with slashes.
|
||||||
|
@ -170,13 +170,7 @@ func (be *Backend) SetListMaxItems(i int) {
|
|||||||
// IsNotExist returns true if the error is caused by a not existing file.
|
// IsNotExist returns true if the error is caused by a not existing file.
|
||||||
func (be *Backend) IsNotExist(err error) bool {
|
func (be *Backend) IsNotExist(err error) bool {
|
||||||
debug.Log("IsNotExist(%T, %#v)", err, err)
|
debug.Log("IsNotExist(%T, %#v)", err, err)
|
||||||
|
return errors.Is(err, storage.ErrObjectNotExist)
|
||||||
if os.IsNotExist(err) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
var gerr *googleapi.Error
|
|
||||||
return errors.As(err, &gerr) && gerr.Code == 404
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Join combines path components with slashes.
|
// Join combines path components with slashes.
|
||||||
|
@ -170,9 +170,6 @@ func isAccessDenied(err error) bool {
|
|||||||
// IsNotExist returns true if the error is caused by a not existing file.
|
// IsNotExist returns true if the error is caused by a not existing file.
|
||||||
func (be *Backend) IsNotExist(err error) bool {
|
func (be *Backend) IsNotExist(err error) bool {
|
||||||
debug.Log("IsNotExist(%T, %#v)", err, err)
|
debug.Log("IsNotExist(%T, %#v)", err, err)
|
||||||
if errors.Is(err, os.ErrNotExist) {
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
var e minio.ErrorResponse
|
var e minio.ErrorResponse
|
||||||
return errors.As(err, &e) && e.Code == "NoSuchKey"
|
return errors.As(err, &e) && e.Code == "NoSuchKey"
|
||||||
|
@ -92,6 +92,7 @@ func (s *Suite) TestConfig(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("did not get expected error for non-existing config")
|
t.Fatalf("did not get expected error for non-existing config")
|
||||||
}
|
}
|
||||||
|
test.Assert(t, b.IsNotExist(err), "IsNotExist() did not recognize error from LoadAll(): %v", err)
|
||||||
|
|
||||||
err = b.Save(context.TODO(), restic.Handle{Type: restic.ConfigFile}, restic.NewByteReader([]byte(testString), b.Hasher()))
|
err = b.Save(context.TODO(), restic.Handle{Type: restic.ConfigFile}, restic.NewByteReader([]byte(testString), b.Hasher()))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -131,11 +132,13 @@ func (s *Suite) TestLoad(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Load() did not return an error for invalid handle")
|
t.Fatalf("Load() did not return an error for invalid handle")
|
||||||
}
|
}
|
||||||
|
test.Assert(t, !b.IsNotExist(err), "IsNotExist() should not accept an invalid handle error: %v", err)
|
||||||
|
|
||||||
err = testLoad(b, restic.Handle{Type: restic.PackFile, Name: "foobar"}, 0, 0)
|
err = testLoad(b, restic.Handle{Type: restic.PackFile, Name: "foobar"}, 0, 0)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("Load() did not return an error for non-existing blob")
|
t.Fatalf("Load() did not return an error for non-existing blob")
|
||||||
}
|
}
|
||||||
|
test.Assert(t, b.IsNotExist(err), "IsNotExist() did not recognize non-existing blob: %v", err)
|
||||||
|
|
||||||
length := rand.Intn(1<<24) + 2000
|
length := rand.Intn(1<<24) + 2000
|
||||||
|
|
||||||
@ -762,6 +765,8 @@ func (s *Suite) TestBackend(t *testing.T) {
|
|||||||
b := s.open(t)
|
b := s.open(t)
|
||||||
defer s.close(t, b)
|
defer s.close(t, b)
|
||||||
|
|
||||||
|
test.Assert(t, !b.IsNotExist(nil), "IsNotExist() recognized nil error")
|
||||||
|
|
||||||
for _, tpe := range []restic.FileType{
|
for _, tpe := range []restic.FileType{
|
||||||
restic.PackFile, restic.KeyFile, restic.LockFile,
|
restic.PackFile, restic.KeyFile, restic.LockFile,
|
||||||
restic.SnapshotFile, restic.IndexFile,
|
restic.SnapshotFile, restic.IndexFile,
|
||||||
@ -780,10 +785,12 @@ func (s *Suite) TestBackend(t *testing.T) {
|
|||||||
// try to stat a not existing blob
|
// try to stat a not existing blob
|
||||||
_, err = b.Stat(context.TODO(), h)
|
_, err = b.Stat(context.TODO(), h)
|
||||||
test.Assert(t, err != nil, "blob data could be extracted before creation")
|
test.Assert(t, err != nil, "blob data could be extracted before creation")
|
||||||
|
test.Assert(t, b.IsNotExist(err), "IsNotExist() did not recognize Stat() error: %v", err)
|
||||||
|
|
||||||
// try to read not existing blob
|
// try to read not existing blob
|
||||||
err = testLoad(b, h, 0, 0)
|
err = testLoad(b, h, 0, 0)
|
||||||
test.Assert(t, err != nil, "blob could be read before creation")
|
test.Assert(t, err != nil, "blob could be read before creation")
|
||||||
|
test.Assert(t, b.IsNotExist(err), "IsNotExist() did not recognize Load() error: %v", err)
|
||||||
|
|
||||||
// try to get string out, should fail
|
// try to get string out, should fail
|
||||||
ret, err = beTest(context.TODO(), b, h)
|
ret, err = beTest(context.TODO(), b, h)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user