mirror of
https://github.com/rclone/rclone.git
synced 2025-03-17 20:27:52 +02:00
onedrive: Factor code into fs.FixRangeOption
This commit is contained in:
parent
c098e25552
commit
d876392d15
@ -1065,18 +1065,7 @@ func (o *Object) Open(options ...fs.OpenOption) (in io.ReadCloser, err error) {
|
|||||||
if o.id == "" {
|
if o.id == "" {
|
||||||
return nil, errors.New("can't download - no id")
|
return nil, errors.New("can't download - no id")
|
||||||
}
|
}
|
||||||
for i := range options {
|
fs.FixRangeOption(options, o.size)
|
||||||
option := options[i]
|
|
||||||
if x, ok := option.(*fs.RangeOption); ok {
|
|
||||||
// Fix RangeOption if requesting a fetch from
|
|
||||||
// the end as it doesn't work with Onedrive.
|
|
||||||
// If start is < 0 then fetch from the end
|
|
||||||
if x.Start < 0 {
|
|
||||||
x = &fs.RangeOption{Start: o.size - x.End, End: -1}
|
|
||||||
options[i] = x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var resp *http.Response
|
var resp *http.Response
|
||||||
opts := rest.Opts{
|
opts := rest.Opts{
|
||||||
Method: "GET",
|
Method: "GET",
|
||||||
|
@ -62,6 +62,24 @@ func (o *RangeOption) Mandatory() bool {
|
|||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// FixRangeOption looks through the slice of options and adjusts any
|
||||||
|
// RangeOption~s found that request a fetch from the end into an
|
||||||
|
// absolute fetch using the size passed in. Some remotes (eg
|
||||||
|
// Onedrive, Box) don't support range requests which index from the
|
||||||
|
// end.
|
||||||
|
func FixRangeOption(options []OpenOption, size int64) {
|
||||||
|
for i := range options {
|
||||||
|
option := options[i]
|
||||||
|
if x, ok := option.(*RangeOption); ok {
|
||||||
|
// If start is < 0 then fetch from the end
|
||||||
|
if x.Start < 0 {
|
||||||
|
x = &RangeOption{Start: size - x.End, End: -1}
|
||||||
|
options[i] = x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// SeekOption defines an HTTP Range option with start only.
|
// SeekOption defines an HTTP Range option with start only.
|
||||||
type SeekOption struct {
|
type SeekOption struct {
|
||||||
Offset int64
|
Offset int64
|
||||||
|
Loading…
x
Reference in New Issue
Block a user