Skip to content

Commit 33add3f

Browse files
ncwyuval-cloudinary
authored andcommitted
fichier: fix server side move - fixes rclone#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
1 parent 8466e58 commit 33add3f

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

backend/fichier/fichier.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -441,23 +441,28 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
441441
fs.Debugf(src, "Can't move - not same remote type")
442442
return nil, fs.ErrorCantMove
443443
}
444+
srcFs := srcObj.fs
444445

445446
// Find current directory ID
446-
_, currentDirectoryID, err := f.dirCache.FindPath(ctx, remote, false)
447+
srcLeaf, srcDirectoryID, err := srcFs.dirCache.FindPath(ctx, srcObj.remote, false)
447448
if err != nil {
448449
return nil, err
449450
}
450451

451452
// Create temporary object
452-
dstObj, leaf, directoryID, err := f.createObject(ctx, remote)
453+
dstObj, dstLeaf, dstDirectoryID, err := f.createObject(ctx, remote)
453454
if err != nil {
454455
return nil, err
455456
}
456457

457458
// If it is in the correct directory, just rename it
458459
var url string
459-
if currentDirectoryID == directoryID {
460-
resp, err := f.renameFile(ctx, srcObj.file.URL, leaf)
460+
if srcDirectoryID == dstDirectoryID {
461+
// No rename needed
462+
if srcLeaf == dstLeaf {
463+
return src, nil
464+
}
465+
resp, err := f.renameFile(ctx, srcObj.file.URL, dstLeaf)
461466
if err != nil {
462467
return nil, fmt.Errorf("couldn't rename file: %w", err)
463468
}
@@ -466,11 +471,16 @@ func (f *Fs) Move(ctx context.Context, src fs.Object, remote string) (fs.Object,
466471
}
467472
url = resp.URLs[0].URL
468473
} else {
469-
folderID, err := strconv.Atoi(directoryID)
474+
dstFolderID, err := strconv.Atoi(dstDirectoryID)
470475
if err != nil {
471476
return nil, err
472477
}
473-
resp, err := f.moveFile(ctx, srcObj.file.URL, folderID, leaf)
478+
rename := dstLeaf
479+
// No rename needed
480+
if srcLeaf == dstLeaf {
481+
rename = ""
482+
}
483+
resp, err := f.moveFile(ctx, srcObj.file.URL, dstFolderID, rename)
474484
if err != nil {
475485
return nil, fmt.Errorf("couldn't move file: %w", err)
476486
}

0 commit comments

Comments
 (0)