fichier: fix server side move - fixes #7856
Some checks are pending
Docker beta build / Build image job (push) Waiting to run

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
This commit is contained in:
Nick Craig-Wood 2024-09-06 16:59:06 +01:00
parent 648afc7df4
commit 3f2074901a

View File

@ -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") fs.Debugf(src, "Can't move - not same remote type")
return nil, fs.ErrorCantMove return nil, fs.ErrorCantMove
} }
srcFs := srcObj.fs
// Find current directory ID // 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 { if err != nil {
return nil, err return nil, err
} }
// Create temporary object // Create temporary object
dstObj, leaf, directoryID, err := f.createObject(ctx, remote) dstObj, dstLeaf, dstDirectoryID, err := f.createObject(ctx, remote)
if err != nil { if err != nil {
return nil, err return nil, err
} }
// If it is in the correct directory, just rename it // If it is in the correct directory, just rename it
var url string var url string
if currentDirectoryID == directoryID { if srcDirectoryID == dstDirectoryID {
resp, err := f.renameFile(ctx, srcObj.file.URL, leaf) // No rename needed
if srcLeaf == dstLeaf {
return src, nil
}
resp, err := f.renameFile(ctx, srcObj.file.URL, dstLeaf)
if err != nil { if err != nil {
return nil, fmt.Errorf("couldn't rename file: %w", err) 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 url = resp.URLs[0].URL
} else { } else {
folderID, err := strconv.Atoi(directoryID) dstFolderID, err := strconv.Atoi(dstDirectoryID)
if err != nil { if err != nil {
return nil, err 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 { if err != nil {
return nil, fmt.Errorf("couldn't move file: %w", err) return nil, fmt.Errorf("couldn't move file: %w", err)
} }