mirror of
https://github.com/restic/restic.git
synced 2025-08-12 11:17:42 +00:00
Reworked Backend.Load API to retry errors during ongoing download
Signed-off-by: Igor Fedorenko <igor@ifedorenko.com>
This commit is contained in:
@@ -25,16 +25,13 @@ func (r rateLimitedBackend) Save(ctx context.Context, h restic.Handle, rd io.Rea
|
||||
return r.Backend.Save(ctx, h, r.limiter.Upstream(rd))
|
||||
}
|
||||
|
||||
func (r rateLimitedBackend) Load(ctx context.Context, h restic.Handle, length int, offset int64) (io.ReadCloser, error) {
|
||||
rc, err := r.Backend.Load(ctx, h, length, offset)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return limitedReadCloser{
|
||||
original: rc,
|
||||
limited: r.limiter.Downstream(rc),
|
||||
}, nil
|
||||
func (r rateLimitedBackend) Load(ctx context.Context, h restic.Handle, length int, offset int64, consumer func(rd io.Reader) error) error {
|
||||
return r.Backend.Load(ctx, h, length, offset, func(rd io.Reader) error {
|
||||
lrd := limitedReadCloser{
|
||||
limited: r.limiter.Downstream(rd),
|
||||
}
|
||||
return consumer(lrd)
|
||||
})
|
||||
}
|
||||
|
||||
type limitedReadCloser struct {
|
||||
@@ -47,6 +44,9 @@ func (l limitedReadCloser) Read(b []byte) (n int, err error) {
|
||||
}
|
||||
|
||||
func (l limitedReadCloser) Close() error {
|
||||
if l.original == nil {
|
||||
return nil
|
||||
}
|
||||
return l.original.Close()
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user