forked from TrueCloudLab/restic
backend: Deduplicate sanity checks for parameters of Load() method
The check is now handled by backend.DefaultLoad. This also guarantees consistent behavior across all backends.
This commit is contained in:
parent
bdcafbc11c
commit
8bfc2519d7
9 changed files with 10 additions and 71 deletions
|
@ -6,6 +6,7 @@ import (
|
|||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
"github.com/restic/restic/internal/debug"
|
||||
"github.com/restic/restic/internal/errors"
|
||||
"github.com/restic/restic/internal/restic"
|
||||
|
@ -62,6 +63,15 @@ func LimitReadCloser(r io.ReadCloser, n int64) *LimitedReadCloser {
|
|||
func DefaultLoad(ctx context.Context, h restic.Handle, length int, offset int64,
|
||||
openReader func(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error),
|
||||
fn func(rd io.Reader) error) error {
|
||||
if err := h.Valid(); err != nil {
|
||||
return backoff.Permanent(err)
|
||||
}
|
||||
if offset < 0 {
|
||||
return errors.New("offset is negative")
|
||||
}
|
||||
if length < 0 {
|
||||
return errors.Errorf("invalid length %d", length)
|
||||
}
|
||||
rd, err := openReader(ctx, h, length, offset)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue