fs/OpenOptions: Make FixRangeOption clamp range to filesize.

This commit is contained in:
Sebastian Bünger 2018-08-07 18:37:21 +02:00 committed by Nick Craig-Wood
parent 10ed455777
commit dd3e912731
1 changed files with 7 additions and 3 deletions

View File

@ -135,9 +135,9 @@ func (o *RangeOption) Decode(size int64) (offset, limit int64) {
// 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.
// absolute fetch using the size passed in and makes sure the range does
// not exceed filesize. 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]
@ -147,6 +147,10 @@ func FixRangeOption(options []OpenOption, size int64) {
x = &RangeOption{Start: size - x.End, End: -1}
options[i] = x
}
if x.End > size {
x = &RangeOption{Start: x.Start, End: size}
options[i] = x
}
}
}
}