Repository navigation
Add --force replacement plumbing and sparse literal stats fix - #2150
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| if context.force_replacements_enabled() { | ||
| context.force_remove_destination(destination, relative, existing)?; | ||
| destination_previously_existed = true; | ||
| existing_metadata = None; | ||
| } else { |
There was a problem hiding this comment.
Keep --existing transfers after forced removal
When a conflicting directory is removed under --force, the code drops existing_metadata to None (lines 78‑82) and the --existing guard immediately below (existing_only_enabled() && existing_metadata.is_none()) interprets the destination as missing, so the copy is skipped after the directory has already been deleted. This means commands such as rsync --existing --force src dest delete the pre‑existing destination (directory, FIFO, device, symlink, etc.) and then refuse to recreate it, leaving nothing behind. The same pattern exists in the special executors (special/device.rs, special/fifo.rs, special/symlink.rs) and in directory/recursive.rs for directory trees. The guard needs to key off “did something exist before we deleted it” (e.g. the existing boolean you already track) instead of the mutated existing_metadata, otherwise --existing cannot be combined with --force without data loss.
Useful? React with 👍 / 👎.
| let relative = parent | ||
| .strip_prefix(self.destination_root()) | ||
| .ok() | ||
| .filter(|path| !path.as_os_str().is_empty()); | ||
| self.force_remove_destination(parent, relative, &existing)?; | ||
| Err(LocalCopyError::io( | ||
| "create parent directory", | ||
| parent.to_path_buf(), | ||
| io::Error::from(io::ErrorKind::NotFound), |
There was a problem hiding this comment.
Avoid deleting parent paths when mkpath/implied-dirs are disabled
In prepare_parent_directory you now call force_remove_destination(parent, …) even when allow_creation is false (lines 292‑300). That removes the conflicting parent entry and then immediately returns Err(io::ErrorKind::NotFound) because the user disabled --implied-dirs/--mkpath, so the transfer still fails but their original parent path has been deleted. A user running rsync --no-implied-dirs --force src /tmp/dst/file where /tmp/dst is a file will lose /tmp/dst and still get an error. --force should only delete parent directories when we are allowed to recreate them; otherwise we should surface the error without touching the destination.
Useful? React with 👍 / 👎.
Summary
--force/--no-forceand propagate the option into local copy execution--forceis set, covering files, specials, and symlinksTesting
[Codex Task](