Skip to content

vfs: prevent duplicate file when renaming onto a symlink - fixes #8245 - #9478

Open
eyupcanakman wants to merge 1 commit into
rclone:masterfrom
eyupcanakman:fix/vfs-rename-collision-8245
Open

eyupcanakman wants to merge 1 commit into
rclone:masterfrom
eyupcanakman:fix/vfs-rename-collision-8245

Conversation

@eyupcanakman

@eyupcanakman eyupcanakman commented May 31, 2026 •

Copy link
Copy Markdown

What does this change do?

When --vfs-links is enabled the VFS keys items by the logical leaf with .rclonelink stripped, so renaming a file onto an existing symlink (or vice versa) left both name and name.rclonelink on a remote that stores the link as a .rclonelink file, with one node visible in the mount.

With --vfs-links, Dir.Rename now stats the destination first and returns EEXIST when exactly one of the source and the destination is a symlink. It uses the same stat handling as Dir.Create and Dir.Mkdir. Other renames, and everything without --vfs-links, behave as before. This follows corner case #3 in the existing tests, so a rename that would replace a symlink with a file or directory (or the reverse) fails instead.

Four skipped tests in vfs/vfstest/file.go are enabled, plus one same-directory case for the demo in the issue. All five fail on master and pass with the fix. I also ran it through rclone serve sftp on a plain local remote with --vfs-links. On master rename file2 symlink leaves both symlink and symlink.rclonelink. With the fix the rename fails and the remote is unchanged.

Linked issue

Fixes #8245

Checklist

  • This change is trivial OR it has been discussed and agreed in the linked issue.
  • I have read the contribution guidelines.
  • (If I used AI tools to help write this code) I have read and understood the AI-assisted contributions guidance, and I have tested and take ownership of this change myself.
  • I have added tests for all changes in this PR if appropriate.
  • I have added documentation for the changes if appropriate.
  • All commit messages are in house style.
  • (Backend changes only) test_all passes for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.
  • This Pull Request is ready for review.

…ne#8245

Before this change, with `--vfs-links`, renaming a file onto a symlink,
or a symlink onto a file or directory (or the reverse), left both
`name` and `name.rclonelink` on a remote that stores the link as a
`.rclonelink` file, because the VFS lists them under the same name.

After this change, with `--vfs-links`, `Dir.Rename` returns `EEXIST`
when exactly one of the source and the destination is a symlink, and
the skipped symlink move tests are enabled.
@eyupcanakman
eyupcanakman force-pushed the fix/vfs-rename-collision-8245 branch from c83d76e to b4f6a86 Compare November 12, 2026 16:58
@eyupcanakman
eyupcanakman requested a review from ncw as a code owner November 12, 2026 16:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

symlinks support allow to create duplicate named files when moving

1 participant