From 2bcc66c805f7d864ceb51948be64752935682fa9 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Wed, 19 Aug 2020 11:04:12 +0100 Subject: [PATCH] drive: fix duplication of Google docs on server side copy #4517 Before this change, rclone was looking for the file without the extension to see if it existed which meant that it never did. This change checks the destination file exists firsts, before removing the extension. --- backend/drive/drive.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) 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 {