From 55b9a4ed309f6f442cde0a70d50dddc476e91243 Mon Sep 17 00:00:00 2001 From: Fionera Date: Mon, 11 Feb 2019 02:36:47 +0100 Subject: [PATCH] Add ServerSideAcrossConfig Flag and check for it. fixes #2728 --- backend/drive/drive.go | 1 + fs/fs.go | 1 + fs/operations/operations.go | 9 +++++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/drive/drive.go b/backend/drive/drive.go index f60e0ba2f..dc6ea4c8c 100644 --- a/backend/drive/drive.go +++ b/backend/drive/drive.go @@ -907,6 +907,7 @@ func NewFs(name, path string, m configmap.Mapper) (fs.Fs, error) { ReadMimeType: true, WriteMimeType: true, CanHaveEmptyDirectories: true, + ServerSideAcrossConfigs: true, }).Fill(f) // Create a new authorized Drive client. diff --git a/fs/fs.go b/fs/fs.go index 0b1cd5b2a..a25eb1039 100644 --- a/fs/fs.go +++ b/fs/fs.go @@ -409,6 +409,7 @@ type Features struct { BucketBased bool // is bucket based (like s3, swift etc) SetTier bool // allows set tier functionality on objects GetTier bool // allows to retrieve storage tier of objects + ServerSideAcrossConfigs bool // can server side copy between different remotes of the same type // Purge all files in the root and the root directory // diff --git a/fs/operations/operations.go b/fs/operations/operations.go index ec2be9290..f10f7f67b 100644 --- a/fs/operations/operations.go +++ b/fs/operations/operations.go @@ -273,7 +273,7 @@ func Copy(f fs.Fs, dst fs.Object, remote string, src fs.Object) (newDst fs.Objec // Try server side copy first - if has optional interface and // is same underlying remote actionTaken = "Copied (server side copy)" - if doCopy := f.Features().Copy; doCopy != nil && SameConfig(src.Fs(), f) { + if doCopy := f.Features().Copy; doCopy != nil && (SameConfig(src.Fs(), f) || (SameRemoteType(src.Fs(), f) && f.Features().ServerSideAcrossConfigs)) { newDst, err = doCopy(src, remote) if err == nil { dst = newDst @@ -392,7 +392,7 @@ func Move(fdst fs.Fs, dst fs.Object, remote string, src fs.Object) (newDst fs.Ob return newDst, nil } // See if we have Move available - if doMove := fdst.Features().Move; doMove != nil && SameConfig(src.Fs(), fdst) { + if doMove := fdst.Features().Move; doMove != nil && (SameConfig(src.Fs(), fdst) || (SameRemoteType(src.Fs(), fdst) && fdst.Features().ServerSideAcrossConfigs)) { // Delete destination if it exists if dst != nil { err = DeleteFile(dst) @@ -525,6 +525,11 @@ func DeleteFiles(toBeDeleted fs.ObjectsChan) error { return DeleteFilesWithBackupDir(toBeDeleted, nil) } +// SameRemoteType returns true if fdst and fsrc are the same type +func SameRemoteType(fdst, fsrc fs.Info) bool { + return fmt.Sprintf("%T", fdst) == fmt.Sprintf("%T", fsrc) +} + // SameConfig returns true if fdst and fsrc are using the same config // file entry func SameConfig(fdst, fsrc fs.Info) bool {