From 3f2074901ace9ef376199d5c486bd8d212a94873 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Fri, 6 Sep 2024 16:59:06 +0100 Subject: [PATCH] fichier: fix server side move - fixes #7856 The server side move had a combination of bugs - Fichier changed the API disallowing a move to the same name - Rclone was using the wrong object for some operations --- backend/fichier/fichier.go | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/backend/fichier/fichier.go b/backend/fichier/fichier.go index 4a2caf5bf..5ebc8a6db 100644 --- a/backend/fichier/fichier.go +++ b/backend/fichier/fichier.go @@ -441,23 +441,28 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, fs.Debugf(src, "Can't move - not same remote type") return nil, fs.ErrorCantMove } + srcFs := srcObj.fs // Find current directory ID - _, currentDirectoryID, err := f.dirCache.FindPath(ctx, remote, false) + srcLeaf, srcDirectoryID, err := srcFs.dirCache.FindPath(ctx, srcObj.remote, false) if err != nil { return nil, err } // Create temporary object - dstObj, leaf, directoryID, err := f.createObject(ctx, remote) + dstObj, dstLeaf, dstDirectoryID, err := f.createObject(ctx, remote) if err != nil { return nil, err } // If it is in the correct directory, just rename it var url string - if currentDirectoryID == directoryID { - resp, err := f.renameFile(ctx, srcObj.file.URL, leaf) + if srcDirectoryID == dstDirectoryID { + // No rename needed + if srcLeaf == dstLeaf { + return src, nil + } + resp, err := f.renameFile(ctx, srcObj.file.URL, dstLeaf) if err != nil { return nil, fmt.Errorf("couldn't rename file: %w", err) } @@ -466,11 +471,16 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object, } url = resp.URLs[0].URL } else { - folderID, err := strconv.Atoi(directoryID) + dstFolderID, err := strconv.Atoi(dstDirectoryID) if err != nil { return nil, err } - resp, err := f.moveFile(ctx, srcObj.file.URL, folderID, leaf) + rename := dstLeaf + // No rename needed + if srcLeaf == dstLeaf { + rename = "" + } + resp, err := f.moveFile(ctx, srcObj.file.URL, dstFolderID, rename) if err != nil { return nil, fmt.Errorf("couldn't move file: %w", err) }