Skip to content

sync: fix sync failing when a file is replaced by a directory or vice versa - #10361

Open
adios-404 wants to merge 1 commit into
rclone:masterfrom
adios-404:fix-2231
Open

adios-404 wants to merge 1 commit into
rclone:masterfrom
adios-404:fix-2231

Conversation

@adios-404

Copy link
Copy Markdown

What does this change do?

If a file in the source is replaced by a directory of the same name, or the reverse, sync to a destination where the two can't coexist fails on every run, because nothing is deleted after an error.

march now reports the two as a match. Its sort suffix becomes "/D" and "/F" so that nothing sorts between a directory and a file of the same name (so "file" is now processed before "file2"). Sync then deletes what is in the destination before copying, as suggested in the issue.

Only when sync is deleting, and not with --immutable, --ignore-existing, --max-depth, --suffix alone, after an error, if the source file can't be opened, or if filters would leave part of a directory behind. --backup-dir, --max-delete and --dry-run are obeyed. copy and move are unchanged.

Overlaps with #9696.

Linked issue

Fixes #2231

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.

… versa - fixes rclone#2231

If a file in the source was replaced by a directory with the same
name, or a directory by a file, syncing to a destination where the two
can't both exist failed. On the local backend the errors were

    Failed to copy: mkdir dst/name: not a directory
    partial file rename failed: can't move object - incompatible remotes

and as there had been an error nothing was deleted from the
destination, so running the sync again failed in the same way.

march reported the two as unrelated: something only in the source and
something only in the destination. The file was copied before what
was in its way was deleted.

This adds MatchTypeChanges to march to report a file and a directory
with the same name as a match, unless the side with the directory has
a file of that name too. The suffix march adds to names to sort
directories before files now starts with a "/", which can't be in a
name, so that nothing sorts between a directory and a file with the
same name. This changes the order entries are processed in where one
name is the start of another: "file" now comes before "file2".

sync sets MatchTypeChanges when it is deleting, for destinations which
aren't bucket based and can't have duplicate names, and deletes what
is in the destination before copying what is in the source. This is
the one case where sync deletes before copying whatever --delete-after
says, as there is no other way to make the destination match. Deleting
obeys --backup-dir, --max-delete and --dry-run, and what is deleted
is reported as missing from the source as other deletes are.

What is in the destination is left alone, and the two are synced as
they were before:

- with --immutable, --ignore-existing or --max-depth
- with --suffix and no --backup-dir, which would only rename what is
  in the way
- if a directory has files in it which the filters exclude and
  --delete-excluded isn't set
- if the file in the source can't be opened
- if there has already been an error, as for other deletes

copy and move are unchanged.

With --track-renames a file deleted to make way can no longer be the
source of a rename, so is transferred again if it was moved.
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.

Sync fails when a new file has the same name as an old directory

1 participant