diff --git a/internal/backend/rest/rest.go b/internal/backend/rest/rest.go index 5b59b8e4f..f743c3e50 100644 --- a/internal/backend/rest/rest.go +++ b/internal/backend/rest/rest.go @@ -17,6 +17,7 @@ import ( "github.com/restic/restic/internal/backend/util" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" + "github.com/restic/restic/internal/feature" ) // make sure the rest backend implements backend.Backend @@ -245,7 +246,7 @@ func (b *Backend) openReader(ctx context.Context, h backend.Handle, length int, return nil, &restError{h, resp.StatusCode, resp.Status} } - if length > 0 && resp.ContentLength != int64(length) { + if feature.Flag.Enabled(feature.BackendErrorRedesign) && length > 0 && resp.ContentLength != int64(length) { return nil, &restError{h, http.StatusRequestedRangeNotSatisfiable, "partial out of bounds read"} } diff --git a/internal/backend/s3/s3.go b/internal/backend/s3/s3.go index afe1653f6..a2c95ac32 100644 --- a/internal/backend/s3/s3.go +++ b/internal/backend/s3/s3.go @@ -17,6 +17,7 @@ import ( "github.com/restic/restic/internal/backend/util" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" + "github.com/restic/restic/internal/feature" "github.com/minio/minio-go/v7" "github.com/minio/minio-go/v7/pkg/credentials" @@ -404,7 +405,7 @@ func (be *Backend) openReader(ctx context.Context, h backend.Handle, length int, return nil, err } - if length > 0 { + if feature.Flag.Enabled(feature.BackendErrorRedesign) && length > 0 { if info.Size > 0 && info.Size != int64(length) { _ = rd.Close() return nil, minio.ErrorResponse{Code: "InvalidRange", Message: "restic-file-too-short"} diff --git a/internal/backend/sftp/sftp.go b/internal/backend/sftp/sftp.go index 7bab25bed..b624c5060 100644 --- a/internal/backend/sftp/sftp.go +++ b/internal/backend/sftp/sftp.go @@ -20,6 +20,7 @@ import ( "github.com/restic/restic/internal/backend/util" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" + "github.com/restic/restic/internal/feature" "github.com/cenkalti/backoff/v4" "github.com/pkg/sftp" @@ -426,7 +427,7 @@ func (r *SFTP) checkNoSpace(dir string, size int64, origErr error) error { // given offset. func (r *SFTP) Load(ctx context.Context, h backend.Handle, length int, offset int64, fn func(rd io.Reader) error) error { return util.DefaultLoad(ctx, h, length, offset, r.openReader, func(rd io.Reader) error { - if length == 0 { + if length == 0 || !feature.Flag.Enabled(feature.BackendErrorRedesign) { return fn(rd) } diff --git a/internal/backend/swift/swift.go b/internal/backend/swift/swift.go index 616fcf3b7..1643af7fc 100644 --- a/internal/backend/swift/swift.go +++ b/internal/backend/swift/swift.go @@ -19,6 +19,7 @@ import ( "github.com/restic/restic/internal/backend/util" "github.com/restic/restic/internal/debug" "github.com/restic/restic/internal/errors" + "github.com/restic/restic/internal/feature" "github.com/ncw/swift/v2" ) @@ -156,7 +157,7 @@ func (be *beSwift) openReader(ctx context.Context, h backend.Handle, length int, return nil, fmt.Errorf("conn.ObjectOpen: %w", err) } - if length > 0 { + if feature.Flag.Enabled(feature.BackendErrorRedesign) && length > 0 { // get response length, but don't cause backend calls cctx, cancel := context.WithCancel(context.Background()) cancel()