smb: fix spurious "Directory already exists" errors when moving directories - fixes #9680

DirMove returned fs.ErrorDirExists for any error from the destination
existence check not just when the destination actually exists. That
made sync silently fall back to file-by-file moves and masked the real
failure.

Return the underlying error instead when the check fails for any other
reason.
This commit is contained in:
Nick Craig-Wood
2026-07-30 17:50:45 +01:00
parent 088f68f3c3
commit 8772c94011
+6 -4
View File
@@ -439,11 +439,13 @@ func (f *Fs) DirMove(ctx context.Context, src fs.Fs, srcRemote, dstRemote string
defer f.putConnection(&cn, err)
_, err = cn.smbShare.Stat(f.toSambaPath(dstPath))
if os.IsNotExist(err) {
err = cn.smbShare.Rename(f.toSambaPath(srcPath), f.toSambaPath(dstPath))
return translateError(err, true)
if err == nil {
return fs.ErrorDirExists
} else if !os.IsNotExist(err) {
return fmt.Errorf("failed to check destination directory: %w", err)
}
return fs.ErrorDirExists
err = cn.smbShare.Rename(f.toSambaPath(srcPath), f.toSambaPath(dstPath))
return translateError(err, true)
}
// List files and directories in a directory