"rsync for cloud storage" - Google Drive, S3, Dropbox, Backblaze B2, One Drive, Swift, Hubic, Wasabi, Google Cloud Storage, Azure Blob, Azure Files, Yandex Files
Go azure-blobazure-blob-storageazure-filesbackblaze-b2cloud-storagedropboxencryptionftpfuse-filesystemgogolanggoogle-cloud-storagegoogle-driveonedriveopenstack-swiftrclones3sftpsyncwebdav
drive: add --drive-chunk-size and --drive-upload-cutoff parameters
Nick Craig-Wood7c120b8bc51f
diff --git a/drive/drive.go b/drive/drive.goindex 8002600d5..e1e50fb86 100644--- a/drive/drive.go+++ b/drive/drive.go@@ -39,6 +39,10 @@ const (var (// FlagsdriveFullList = pflag.BoolP("drive-full-list", "", true, "Use a full listing for directory list. More data but usually quicker.")+ // chunkSize is the size of the chunks created during a resumable upload and should be a power of two.+ // 1<<18 is the minimum size supported by the Google uploader, and there is no maximum.+ chunkSize = fs.SizeSuffix(256 * 1024)+ driveUploadCutoff = chunkSize// Description of how to auth for this appdriveAuth = &googleauth.Auth{Scope: "https://www.googleapis.com/auth/drive",@@ -63,6 +67,8 @@ func init() {Help: "Google Application Client Secret - leave blank to use rclone's.",}},})+ pflag.VarP(&driveUploadCutoff, "drive-upload-cutoff", "", "Cutoff for switching to chunked upload")+ pflag.VarP(&chunkSize, "drive-chunk-size", "", "Upload chunk size. Must a power of 2 >= 256k.")}// FsDrive represents a remote drive server@@ -293,8 +299,27 @@ OUTER:return}+// Returns true of x is a power of 2 or zero+func isPowerOfTwo(x int64) bool {+ switch {+ case x == 0:+ return true+ case x < 0:+ return false+ default:+ return (x & (x - 1)) == 0+ }+}+// NewFs contstructs an FsDrive from the path, container:pathfunc NewFs(name, path string) (fs.Fs, error) {+ if !isPowerOfTwo(int64(chunkSize)) {+ return nil, fmt.Errorf("drive: chunk size %v isn't a power of two", chunkSize)+ }+ if chunkSize < 256*1024 {+ return nil, fmt.Errorf("drive: chunk size can't be less than 256k - was %v", chunkSize)+ }+t, err := driveAuth.NewTransport(name)if err != nil {return nil, err@@ -730,7 +755,7 @@ func (f *FsDrive) Put(in io.Reader, remote string, modTime time.Time, size int64}var info *drive.File- if false {+ if size == 0 || size < int64(driveUploadCutoff) {// Make the API request to upload metadata and file data.// Don't retry, return a retry error insteadf.beginCall()@@ -970,7 +995,7 @@ func (o *FsObjectDrive) Update(in io.Reader, modTime time.Time, size int64) erro// Make the API request to upload metadata and file data.var err errorvar info *drive.File- if false {+ if size == 0 || size < int64(driveUploadCutoff) {// Don't retry, return a retry error insteado.drive.beginCall()info, err = o.drive.svc.Files.Update(updateInfo.Id, updateInfo).SetModifiedDate(true).Media(in).Do()diff --git a/drive/upload.go b/drive/upload.goindex 5e4450120..3e91b8e5e 100644--- a/drive/upload.go+++ b/drive/upload.go@@ -31,10 +31,6 @@ const (// Number of times to try each chunkmaxTries = 10-- // chunkSize is the size of the chunks created during a resumable upload and should be a power of two.- // 1<<18 is the minimum size supported by the Google uploader, and there is no maximum.- chunkSize int64 = 1 << 18)// resumableUpload is used by the generated APIs to provide resumable uploads.@@ -194,8 +190,8 @@ func (rx *resumableUpload) Upload() (*drive.File, error) {var StatusCode intfor start < rx.ContentLength {reqSize := rx.ContentLength - start- if reqSize >= chunkSize {- reqSize = chunkSize+ if reqSize >= int64(chunkSize) {+ reqSize = int64(chunkSize)} else {buf = buf[:reqSize]}