mirror of
https://github.com/restic/restic.git
synced 2025-07-28 14:53:48 +00:00
backend: Ensure Reader is closed on error
This commit is contained in:
parent
4a354befe5
commit
82d9163955
@ -28,7 +28,8 @@ type Backend interface {
|
|||||||
|
|
||||||
// Get returns a reader that yields the contents of the file at h at the
|
// Get returns a reader that yields the contents of the file at h at the
|
||||||
// given offset. If length is nonzero, only a portion of the file is
|
// given offset. If length is nonzero, only a portion of the file is
|
||||||
// returned. rd must be closed after use.
|
// returned. rd must be closed after use. If an error is returned, the
|
||||||
|
// ReadCloser must be nil.
|
||||||
Get(h Handle, length int, offset int64) (io.ReadCloser, error)
|
Get(h Handle, length int, offset int64) (io.ReadCloser, error)
|
||||||
|
|
||||||
// Stat returns information about the File identified by h.
|
// Stat returns information about the File identified by h.
|
||||||
|
@ -214,6 +214,7 @@ func (be *s3) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, err
|
|||||||
debug.Log("Get %v: pass on object", h)
|
debug.Log("Get %v: pass on object", h)
|
||||||
_, err = obj.Seek(offset, 0)
|
_, err = obj.Seek(offset, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = obj.Close()
|
||||||
return nil, errors.Wrap(err, "obj.Seek")
|
return nil, errors.Wrap(err, "obj.Seek")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -223,10 +224,12 @@ func (be *s3) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, err
|
|||||||
// otherwise use a buffer with ReadAt
|
// otherwise use a buffer with ReadAt
|
||||||
info, err := obj.Stat()
|
info, err := obj.Stat()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = obj.Close()
|
||||||
return nil, errors.Wrap(err, "obj.Stat")
|
return nil, errors.Wrap(err, "obj.Stat")
|
||||||
}
|
}
|
||||||
|
|
||||||
if offset > info.Size {
|
if offset > info.Size {
|
||||||
|
_ = obj.Close()
|
||||||
return nil, errors.Errorf("offset larger than file size")
|
return nil, errors.Errorf("offset larger than file size")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -245,6 +248,7 @@ func (be *s3) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, err
|
|||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
_ = obj.Close()
|
||||||
return nil, errors.Wrap(err, "obj.ReadAt")
|
return nil, errors.Wrap(err, "obj.ReadAt")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -419,7 +419,7 @@ func (r *SFTP) Get(h restic.Handle, length int, offset int64) (io.ReadCloser, er
|
|||||||
if offset > 0 {
|
if offset > 0 {
|
||||||
_, err = f.Seek(offset, 0)
|
_, err = f.Seek(offset, 0)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
f.Close()
|
_ = f.Close()
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user