Skip to content

Add --force replacement plumbing and sparse literal stats fix - #2150

Merged
oferchen merged 1 commit into
masterfrom
implement-rsync-3.4.1-behavioral-parity-in-rust
Nov 14, 2025
Merged

oferchen merged 1 commit into
masterfrom
implement-rsync-3.4.1-behavioral-parity-in-rust

Conversation

@oferchen

@oferchen oferchen commented Nov 14, 2025 •

Copy link
Copy Markdown
Owner

Summary

  • add CLI and core plumbing for --force/--no-force and propagate the option into local copy execution
  • allow the engine to remove conflicting destinations and parent directories when --force is set, covering files, specials, and symlinks
  • correct sparse transfer literal byte accounting and extend tests to cover the new behaviour

Testing

  • cargo test -p engine
  • cargo test -p cli

[Codex Task](

@oferchen
oferchen merged commit 8420580 into master Nov 14, 2025
@oferchen
oferchen deleted the implement-rsync-3.4.1-behavioral-parity-in-rust branch November 14, 2025 13:50

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +78 to +82
if context.force_replacements_enabled() {
context.force_remove_destination(destination, relative, existing)?;
destination_previously_existed = true;
existing_metadata = None;
} else {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Comment on lines +292 to +300
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),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant