From 17dabf7a99ce3c5d29cd1157088d17b44a97d120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=B6ller?= Date: Tue, 23 Jan 2018 21:09:11 +0100 Subject: [PATCH] ftp: fix RangeOption support in Open #1825 --- backend/ftp/ftp.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/backend/ftp/ftp.go b/backend/ftp/ftp.go index eb7da5c1f..7f333550d 100644 --- a/backend/ftp/ftp.go +++ b/backend/ftp/ftp.go @@ -16,6 +16,7 @@ import ( "github.com/ncw/rclone/fs/config" "github.com/ncw/rclone/fs/config/obscure" "github.com/ncw/rclone/fs/hash" + "github.com/ncw/rclone/lib/readers" "github.com/pkg/errors" ) @@ -633,11 +634,13 @@ func (f *ftpReadCloser) Close() error { func (o *Object) Open(options ...fs.OpenOption) (rc io.ReadCloser, err error) { // defer fs.Trace(o, "")("rc=%v, err=%v", &rc, &err) path := path.Join(o.fs.root, o.remote) - var offset int64 + 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) @@ -653,7 +656,7 @@ func (o *Object) Open(options ...fs.OpenOption) (rc io.ReadCloser, err error) { o.fs.putFtpConnection(&c, err) return nil, errors.Wrap(err, "open") } - rc = &ftpReadCloser{rc: fd, c: c, f: o.fs} + rc = &ftpReadCloser{rc: readers.NewLimitedReadCloser(fd, limit), c: c, f: o.fs} return rc, nil }