From ceea6753eeaaed7cceb08041c4741b0784b8a0ac Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 8 Nov 2024 14:01:51 +0000 Subject: [PATCH] dropbox: fix server side copying over existing object This was causing a conflict error. This was fixed by renaming the existing file first and if the copy was successful deleting it, or renaming it back. --- backend/dropbox/dropbox.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/dropbox/dropbox.go b/backend/dropbox/dropbox.go index f2f1fc852..520c5dbc2 100644 --- a/backend/dropbox/dropbox.go +++ b/backend/dropbox/dropbox.go @@ -47,6 +47,7 @@ import ( "github.com/rclone/rclone/fs/config/obscure" "github.com/rclone/rclone/fs/fserrors" "github.com/rclone/rclone/fs/hash" + "github.com/rclone/rclone/fs/operations" "github.com/rclone/rclone/lib/batcher" "github.com/rclone/rclone/lib/encoder" "github.com/rclone/rclone/lib/oauthutil" @@ -1020,13 +1021,20 @@ func (f *Fs) Precision() time.Duration { // Will only be called if src.Fs().Name() == f.Name() // // If it isn't possible then return fs.ErrorCantCopy -func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, error) { +func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (dst fs.Object, err error) { srcObj, ok := src.(*Object) if !ok { fs.Debugf(src, "Can't copy - not same remote type") return nil, fs.ErrorCantCopy } + // Find and remove existing object + cleanup, err := operations.RemoveExisting(ctx, f, remote, "server side copy") + if err != nil { + return nil, err + } + defer cleanup(&err) + // Temporary Object under construction dstObj := &Object{ fs: f, @@ -1040,7 +1048,6 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, ToPath: f.opt.Enc.FromStandardPath(dstObj.remotePath()), }, } - var err error var result *files.RelocationResult err = f.pacer.Call(func() (bool, error) { result, err = f.srv.CopyV2(&arg)