diff --git a/internal/backend/azure/azure.go b/internal/backend/azure/azure.go index 682534cd2..33162c227 100644 --- a/internal/backend/azure/azure.go +++ b/internal/backend/azure/azure.go @@ -10,11 +10,13 @@ import ( "path" "strings" - "github.com/Azure/azure-sdk-for-go/storage" "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" + + "github.com/Azure/azure-sdk-for-go/storage" + "github.com/cenkalti/backoff/v4" ) // Backend stores data on an azure endpoint. @@ -119,7 +121,7 @@ func (be *Backend) Path() string { // Save stores data in the backend at the handle. func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error { if err := h.Valid(); err != nil { - return err + return backoff.Permanent(err) } objName := be.Filename(h) @@ -219,7 +221,7 @@ func (be *Backend) Load(ctx context.Context, h restic.Handle, length int, offset func (be *Backend) openReader(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { debug.Log("Load %v, length %v, offset %v from %v", h, length, offset, be.Filename(h)) if err := h.Valid(); err != nil { - return nil, err + return nil, backoff.Permanent(err) } if offset < 0 { diff --git a/internal/backend/b2/b2.go b/internal/backend/b2/b2.go index be1adc160..f6d4331c8 100644 --- a/internal/backend/b2/b2.go +++ b/internal/backend/b2/b2.go @@ -11,6 +11,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" + "github.com/cenkalti/backoff/v4" "github.com/kurin/blazer/b2" ) @@ -150,7 +151,7 @@ func (be *b2Backend) Load(ctx context.Context, h restic.Handle, length int, offs func (be *b2Backend) openReader(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { debug.Log("Load %v, length %v, offset %v from %v", h, length, offset, be.Filename(h)) if err := h.Valid(); err != nil { - return nil, err + return nil, backoff.Permanent(err) } if offset < 0 { @@ -189,7 +190,7 @@ func (be *b2Backend) Save(ctx context.Context, h restic.Handle, rd restic.Rewind defer cancel() if err := h.Valid(); err != nil { - return err + return backoff.Permanent(err) } be.sem.GetToken() diff --git a/internal/backend/local/local.go b/internal/backend/local/local.go index 4930264fd..acb4751fc 100644 --- a/internal/backend/local/local.go +++ b/internal/backend/local/local.go @@ -85,7 +85,7 @@ func (b *Local) IsNotExist(err error) bool { func (b *Local) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) (err error) { debug.Log("Save %v", h) if err := h.Valid(); err != nil { - return err + return backoff.Permanent(err) } filename := b.Filename(h) @@ -162,7 +162,7 @@ func (b *Local) Load(ctx context.Context, h restic.Handle, length int, offset in func (b *Local) openReader(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { debug.Log("Load %v, length %v, offset %v", h, length, offset) if err := h.Valid(); err != nil { - return nil, err + return nil, backoff.Permanent(err) } if offset < 0 { @@ -193,7 +193,7 @@ func (b *Local) openReader(ctx context.Context, h restic.Handle, length int, off func (b *Local) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error) { debug.Log("Stat %v", h) if err := h.Valid(); err != nil { - return restic.FileInfo{}, err + return restic.FileInfo{}, backoff.Permanent(err) } fi, err := fs.Stat(b.Filename(h)) diff --git a/internal/backend/mem/mem_backend.go b/internal/backend/mem/mem_backend.go index fc7196f0b..8378630fa 100644 --- a/internal/backend/mem/mem_backend.go +++ b/internal/backend/mem/mem_backend.go @@ -8,10 +8,11 @@ import ( "sync" "github.com/restic/restic/internal/backend" + "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/debug" + "github.com/cenkalti/backoff/v4" ) type memMap map[restic.Handle][]byte @@ -61,7 +62,7 @@ func (be *MemoryBackend) IsNotExist(err error) bool { // Save adds new Data to the backend. func (be *MemoryBackend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error { if err := h.Valid(); err != nil { - return err + return backoff.Permanent(err) } be.m.Lock() @@ -94,7 +95,7 @@ func (be *MemoryBackend) Load(ctx context.Context, h restic.Handle, length int, func (be *MemoryBackend) openReader(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { if err := h.Valid(); err != nil { - return nil, err + return nil, backoff.Permanent(err) } be.m.Lock() @@ -133,7 +134,7 @@ func (be *MemoryBackend) Stat(ctx context.Context, h restic.Handle) (restic.File defer be.m.Unlock() if err := h.Valid(); err != nil { - return restic.FileInfo{}, err + return restic.FileInfo{}, backoff.Permanent(err) } if h.Type == restic.ConfigFile { diff --git a/internal/backend/rest/rest.go b/internal/backend/rest/rest.go index a294cb35f..76feb3a11 100644 --- a/internal/backend/rest/rest.go +++ b/internal/backend/rest/rest.go @@ -13,11 +13,12 @@ import ( "golang.org/x/net/context/ctxhttp" + "github.com/restic/restic/internal/backend" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" - "github.com/restic/restic/internal/backend" + "github.com/cenkalti/backoff/v4" ) // make sure the rest backend implements restic.Backend @@ -109,7 +110,7 @@ func (b *Backend) Location() string { // Save stores data in the backend at the handle. func (b *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error { if err := h.Valid(); err != nil { - return err + return backoff.Permanent(err) } ctx, cancel := context.WithCancel(ctx) @@ -204,7 +205,7 @@ func (b *Backend) Load(ctx context.Context, h restic.Handle, length int, offset func (b *Backend) openReader(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { debug.Log("Load %v, length %v, offset %v", h, length, offset) if err := h.Valid(); err != nil { - return nil, err + return nil, backoff.Permanent(err) } if offset < 0 { @@ -256,7 +257,7 @@ func (b *Backend) openReader(ctx context.Context, h restic.Handle, length int, o // Stat returns information about a blob. func (b *Backend) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, error) { if err := h.Valid(); err != nil { - return restic.FileInfo{}, err + return restic.FileInfo{}, backoff.Permanent(err) } req, err := http.NewRequest(http.MethodHead, b.Filename(h), nil) @@ -311,7 +312,7 @@ func (b *Backend) Test(ctx context.Context, h restic.Handle) (bool, error) { // Remove removes the blob with the given name and type. func (b *Backend) Remove(ctx context.Context, h restic.Handle) error { if err := h.Valid(); err != nil { - return err + return backoff.Permanent(err) } req, err := http.NewRequest("DELETE", b.Filename(h), nil) diff --git a/internal/backend/s3/s3.go b/internal/backend/s3/s3.go index 08d3b7aa7..83d784813 100644 --- a/internal/backend/s3/s3.go +++ b/internal/backend/s3/s3.go @@ -12,13 +12,13 @@ import ( "time" "github.com/restic/restic/internal/backend" + "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" + "github.com/cenkalti/backoff/v4" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" - - "github.com/restic/restic/internal/debug" ) // Backend stores data on an S3 endpoint. @@ -260,7 +260,7 @@ func (be *Backend) Save(ctx context.Context, h restic.Handle, rd restic.RewindRe debug.Log("Save %v", h) if err := h.Valid(); err != nil { - return err + return backoff.Permanent(err) } objName := be.Filename(h) @@ -300,7 +300,7 @@ func (be *Backend) Load(ctx context.Context, h restic.Handle, length int, offset func (be *Backend) openReader(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { debug.Log("Load %v, length %v, offset %v from %v", h, length, offset, be.Filename(h)) if err := h.Valid(); err != nil { - return nil, err + return nil, backoff.Permanent(err) } if offset < 0 { diff --git a/internal/backend/sftp/sftp.go b/internal/backend/sftp/sftp.go index 4a0c1695b..e395de60d 100644 --- a/internal/backend/sftp/sftp.go +++ b/internal/backend/sftp/sftp.go @@ -264,7 +264,7 @@ func (r *SFTP) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader } if err := h.Valid(); err != nil { - return err + return backoff.Permanent(err) } filename := r.Filename(h) @@ -311,7 +311,7 @@ func (r *SFTP) Load(ctx context.Context, h restic.Handle, length int, offset int func (r *SFTP) openReader(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { debug.Log("Load %v, length %v, offset %v", h, length, offset) if err := h.Valid(); err != nil { - return nil, err + return nil, backoff.Permanent(err) } if offset < 0 { @@ -346,7 +346,7 @@ func (r *SFTP) Stat(ctx context.Context, h restic.Handle) (restic.FileInfo, erro } if err := h.Valid(); err != nil { - return restic.FileInfo{}, err + return restic.FileInfo{}, backoff.Permanent(err) } fi, err := r.c.Lstat(r.Filename(h)) diff --git a/internal/backend/swift/swift.go b/internal/backend/swift/swift.go index fcbbec5e5..488ccbd14 100644 --- a/internal/backend/swift/swift.go +++ b/internal/backend/swift/swift.go @@ -14,6 +14,7 @@ import ( "github.com/restic/restic/internal/errors" "github.com/restic/restic/internal/restic" + "github.com/cenkalti/backoff/v4" "github.com/ncw/swift" ) @@ -122,7 +123,7 @@ func (be *beSwift) Load(ctx context.Context, h restic.Handle, length int, offset func (be *beSwift) openReader(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) { debug.Log("Load %v, length %v, offset %v", h, length, offset) if err := h.Valid(); err != nil { - return nil, err + return nil, backoff.Permanent(err) } if offset < 0 { @@ -162,7 +163,7 @@ func (be *beSwift) openReader(ctx context.Context, h restic.Handle, length int, // Save stores data in the backend at the handle. func (be *beSwift) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader) error { if err := h.Valid(); err != nil { - return err + return backoff.Permanent(err) } objName := be.Filename(h)