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

onedrive: allow --onedrive-upload-cutoff up to the documented limit of 250 MiB

Can Arslan3fe205796a84
diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go
index 6b6356c4c..1ed2f1278 100644
--- a/backend/onedrive/onedrive.go
+++ b/backend/onedrive/onedrive.go
@@ -56,7 +56,15 @@ const (
driveTypeSharepoint = "documentLibrary"
defaultChunkSize = 10 * fs.Mebi
chunkSizeMultiple = 320 * fs.Kibi
- maxSinglePartSize = 4 * fs.Mebi
+ // maxSinglePartSize is the size at which Graph stops accepting an upload in a
+ // single request (PUT /items/{id}/content). Microsoft documents this as
+ // "250 MB", see
+ // https://learn.microsoft.com/en-us/graph/api/driveitem-put-content
+ // Measured against SharePoint Online the figure is binary and exclusive: a
+ // body of 262143999 bytes is accepted, one of 262144000 is not. That matches
+ // upload_cutoff being an exclusive threshold in Update below, so a cutoff of
+ // exactly 250Mi sends everything the server would refuse to multipart.
+ maxSinglePartSize = 250 * fs.Mebi
regionGlobal = "global"
regionUS = "us"
@@ -2786,13 +2794,13 @@ func (o *Object) uploadMultipart(ctx context.Context, in io.Reader, src fs.Objec
return info, o.setMetaData(info)
}
-// Update the content of a remote file within 4 MiB size in one single request
+// Update the content of a remote file smaller than maxSinglePartSize in one single request
// (currently only used when size is exactly 0)
// This function will set modtime and metadata after uploading, which will create a new version for the remote file
func (o *Object) uploadSinglepart(ctx context.Context, in io.Reader, src fs.ObjectInfo, options ...fs.OpenOption) (info *api.Item, err error) {
size := src.Size()
- if size < 0 || size > int64(maxSinglePartSize) {
- return nil, fmt.Errorf("size passed into uploadSinglepart must be >= 0 and <= %v", maxSinglePartSize)
+ if size < 0 || size >= int64(maxSinglePartSize) {
+ return nil, fmt.Errorf("size passed into uploadSinglepart must be >= 0 and < %v", maxSinglePartSize)
}
fs.Debugf(o, "Starting singlepart upload")
diff --git a/backend/onedrive/onedrive_internal_test.go b/backend/onedrive/onedrive_internal_test.go
index 01ed7d3eb..900a63da0 100644
--- a/backend/onedrive/onedrive_internal_test.go
+++ b/backend/onedrive/onedrive_internal_test.go
@@ -516,6 +516,30 @@ func (f *Fs) resetTestDefaults(r *fstest.Run) {
r.Finalise()
}
+// TestCheckUploadCutoff checks the bounds of the --onedrive-upload-cutoff
+// validation, in particular that the documented API maximum is accepted.
+func TestCheckUploadCutoff(t *testing.T) {
+ for _, test := range []struct {
+ in fs.SizeSuffix
+ wantErr bool
+ }{
+ {in: 0, wantErr: false},
+ {in: 4 * fs.Mebi, wantErr: false},
+ // maxSinglePartSize is a legal cutoff even though the server refuses a
+ // body of that size, because the cutoff is an exclusive threshold: at
+ // this setting a file of exactly maxSinglePartSize goes multipart.
+ {in: maxSinglePartSize, wantErr: false},
+ {in: maxSinglePartSize + 1, wantErr: true},
+ } {
+ err := checkUploadCutoff(test.in)
+ if test.wantErr {
+ assert.Error(t, err, test.in.String())
+ } else {
+ assert.NoError(t, err, test.in.String())
+ }
+ }
+}
+
// InternalTest dispatches all internal tests
func (f *Fs) InternalTest(t *testing.T) {
newTestF := func() (*Fs, *fstest.Run) {