mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 08:23:47 +01:00
sftp: fix RangeOption support in Open #1825
This commit is contained in:
parent
a3dd2c691e
commit
9520992a54
@ -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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user