From f307d929a82ab3c05ffb232299d732b0d29bd5fe Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 8 Nov 2024 14:01:51 +0000 Subject: [PATCH] onedrive: 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/onedrive/onedrive.go | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/backend/onedrive/onedrive.go b/backend/onedrive/onedrive.go index f7555017e..97dc8245f 100644 --- a/backend/onedrive/onedrive.go +++ b/backend/onedrive/onedrive.go @@ -1609,7 +1609,7 @@ func (f *Fs) waitForJob(ctx context.Context, location string, o *Object) error { // 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") @@ -1624,11 +1624,18 @@ func (f *Fs) Copy(ctx context.Context, src fs.Object, remote string) (fs.Object, return nil, fs.ErrorCantCopy } - err := srcObj.readMetaData(ctx) + err = srcObj.readMetaData(ctx) if err != nil { return nil, err } + // Find and remove existing object + cleanup, err := operations.RemoveExisting(ctx, f, remote, "server side copy") + if err != nil { + return nil, err + } + defer cleanup(&err) + // Check we aren't overwriting a file on the same remote if srcObj.fs == f { srcPath := srcObj.rootPath()