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

drive: fix duplication of Google docs on server side copy #4517

Nick Craig-Wood2bcc66c805f7
diff --git a/backend/drive/drive.go b/backend/drive/drive.go
index e12953c6e..007dcef6f 100755
--- a/backend/drive/drive.go
+++ b/backend/drive/drive.go
@@ -2272,6 +2272,12 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
return nil, fs.ErrorCantCopy
}
+ // Look to see if there is an existing object before we remove
+ // the extension from the remote
+ existingObject, _ := f.NewObject(ctx, remote)
+
+ // Adjust the remote name to be without the extension if we
+ // are about to create a doc.
if ext != "" {
if !strings.HasSuffix(remote, ext) {
fs.Debugf(src, "Can't copy - not same document type")
@@ -2280,9 +2286,6 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
remote = remote[:len(remote)-len(ext)]
}
- // Look to see if there is an existing object
- existingObject, _ := f.NewObject(ctx, remote)
-
createInfo, err := f.createFileInfo(ctx, remote, src.ModTime(ctx))
if err != nil {
return nil, err
@@ -2329,7 +2332,7 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object,
// change effective, without it is is ignored. This is
// probably some eventual consistency nastiness.
sleepTime := 2 * time.Second
- fs.Debugf(f, "Sleeping for %v before setting the modtime to work around drive bug - see #4517")
+ fs.Debugf(f, "Sleeping for %v before setting the modtime to work around drive bug - see #4517", sleepTime)
time.Sleep(sleepTime)
err = newObject.SetModTime(ctx, src.ModTime(ctx))
if err != nil {