Skip to content

"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files

fs: fix FixRangeOption to do nothing on unknown sized objects

Nick Craig-Woodcf0a72aecd3f
diff --git a/fs/open_options.go b/fs/open_options.go
index 38a391fb9..84e43045c 100644
--- a/fs/open_options.go
+++ b/fs/open_options.go
@@ -142,7 +142,10 @@ func (o *RangeOption) Decode(size int64) (offset, limit int64) {
// It also adjusts any SeekOption~s, turning them into absolute
// RangeOption~s instead.
func FixRangeOption(options []OpenOption, size int64) {
- if size == 0 {
+ if size < 0 {
+ // Can't do anything for unknown length objects
+ return
+ } else if size == 0 {
// if size 0 then remove RangeOption~s
// replacing with a NullOptions~s which won't be rendered
for i := range options {
diff --git a/fs/open_options_test.go b/fs/open_options_test.go
index fefd1f906..829f45c19 100644
--- a/fs/open_options_test.go
+++ b/fs/open_options_test.go
@@ -149,6 +149,16 @@ func TestFixRangeOptions(t *testing.T) {
in: []OpenOption{},
want: []OpenOption{},
},
+ {
+ name: "Unknown size -1",
+ in: []OpenOption{
+ &RangeOption{Start: 1, End: -1},
+ },
+ want: []OpenOption{
+ &RangeOption{Start: 1, End: -1},
+ },
+ size: -1,
+ },
{
name: "Fetch a range with size=0",
in: []OpenOption{