From 9520992a54e939531fa478a7e0ec1ea63492ae4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Tue, 23 Jan 2018 21:21:19 +0100 Subject: [PATCH] sftp: fix RangeOption support in Open #1825 --- backend/sftp/sftp.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/backend/sftp/sftp.go b/backend/sftp/sftp.go index 8b2343bd0..a885c1267 100644 --- a/backend/sftp/sftp.go +++ b/backend/sftp/sftp.go @@ -20,6 +20,7 @@ import ( "github.com/ncw/rclone/fs/config/obscure" "github.com/ncw/rclone/fs/fshttp" "github.com/ncw/rclone/fs/hash" + "github.com/ncw/rclone/lib/readers" "github.com/pkg/errors" "github.com/pkg/sftp" "github.com/xanzy/ssh-agent" @@ -854,12 +855,13 @@ func (file *ObjectReader) Close() (err error) { // Open a remote sftp file object for reading. Seek is supported func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) { - var offset int64 - offset = 0 + var offset, limit int64 for _, option := range options { switch x := option.(type) { case *fs.SeekOption: - offset = x.Offset + offset, limit = x.Offset, 0 + case *fs.RangeOption: + offset, limit = x.Decode(o.Size()) default: if option.Mandatory() { fs.Logf(o, "Unsupported mandatory option: %v", option) @@ -881,10 +883,10 @@ func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) { return nil, errors.Wrap(err, "Open Seek failed") } } - in = &ObjectReader{ + in = readers.NewLimitedReadCloser(&ObjectReader{ object: o, sftpFile: sftpFile, - } + }, limit) return in, nil }