2
2
mirror of https://github.com/octoleo/restic.git synced 2024-06-01 08:30:49 +00:00

sftp: enforce use of optimized upload method

ReadFrom was already used by Save before, this just ensures that this
won't accidentally change in the future.
This commit is contained in:
Michael Eischer 2021-01-01 12:19:48 +01:00
parent 6b5b29dbee
commit 678e75e1c2

View File

@ -287,8 +287,8 @@ func (r *SFTP) Save(ctx context.Context, h restic.Handle, rd restic.RewindReader
return errors.Wrap(err, "OpenFile")
}
// save data
_, err = io.Copy(f, rd)
// save data, make sure to use the optimized sftp upload method
_, err = f.ReadFrom(rd)
if err != nil {
_ = f.Close()
return errors.Wrap(err, "Write")
@ -332,6 +332,8 @@ func (r *SFTP) openReader(ctx context.Context, h restic.Handle, length int, offs
}
if length > 0 {
// unlimited reads usually use io.Copy which needs WriteTo support at the underlying reader
// limited reads are usually combined with io.ReadFull which reads all required bytes into a buffer in one go
return backend.LimitReadCloser(f, int64(length)), nil
}