mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 16:34:30 +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/config/obscure"
|
||||||
"github.com/ncw/rclone/fs/fshttp"
|
"github.com/ncw/rclone/fs/fshttp"
|
||||||
"github.com/ncw/rclone/fs/hash"
|
"github.com/ncw/rclone/fs/hash"
|
||||||
|
"github.com/ncw/rclone/lib/readers"
|
||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/pkg/sftp"
|
"github.com/pkg/sftp"
|
||||||
"github.com/xanzy/ssh-agent"
|
"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
|
// Open a remote sftp file object for reading. Seek is supported
|
||||||
func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
|
func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
|
||||||
var offset int64
|
var offset, limit int64
|
||||||
offset = 0
|
|
||||||
for _, option := range options {
|
for _, option := range options {
|
||||||
switch x := option.(type) {
|
switch x := option.(type) {
|
||||||
case *fs.SeekOption:
|
case *fs.SeekOption:
|
||||||
offset = x.Offset
|
offset, limit = x.Offset, 0
|
||||||
|
case *fs.RangeOption:
|
||||||
|
offset, limit = x.Decode(o.Size())
|
||||||
default:
|
default:
|
||||||
if option.Mandatory() {
|
if option.Mandatory() {
|
||||||
fs.Logf(o, "Unsupported mandatory option: %v", option)
|
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")
|
return nil, errors.Wrap(err, "Open Seek failed")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
in = &ObjectReader{
|
in = readers.NewLimitedReadCloser(&ObjectReader{
|
||||||
object: o,
|
object: o,
|
||||||
sftpFile: sftpFile,
|
sftpFile: sftpFile,
|
||||||
}
|
}, limit)
|
||||||
return in, nil
|
return in, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user