Skip to content

fix: keep local-copy output and exit codes in line with upstream - #8222

Merged
oferchen merged 4 commits into
masterfrom
fix/local-copy-exit-and-output-fidelity
Oct 20, 2026
Merged

oferchen merged 4 commits into
masterfrom
fix/local-copy-exit-and-output-fidelity

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • A local copy that finishes every entry but owes exit 23, 24 or 25 now prints its itemize rows, names and --stats totals before the exit trailer. Before, the CLI dropped the whole summary.
  • The local exit code is decided once, after the run, in upstream's order: 23 outranks 24 outranks 25. A --max-delete cap only counts refusals and never stops the transfer; under --delete-before it used to abort before anything was copied.
  • Under --one-file-system, clearing a directory obstacle for an incoming file keeps a mount point inside it, instead of deleting into the mounted filesystem.

Details

Output on a non-zero exit. The engine returned Err(partial_transfer) at the end of a run that had processed every entry, and the CLI's Err arm discarded the summary. LocalCopyError now carries the completed LocalCopyReport, which core turns into the ClientSummary. execute_transfer renders it through the same path as a clean run, then prints the trailer. An aborted run still has no report. upstream: cleanup.c:210-218 maps io_error / got_xfer_error to the exit code only after the transfer and its output are complete.

Exit precedence and the delete cap.

  • The cap is a counter. The local engine turned the cap into an error. recursive/mod.rs deferred it per directory, with comments claiming "25 outranks 23/24", the reverse of cleanup.c:210-218. It also aborted the remaining sources, and under --delete-before the whole transfer. The cap is now a run-wide skipped_deletes counter (delete.c:217-219), the deferral machinery is gone, and completed_run_exit_error() applies upstream's order once.
  • Reporting. The skipped total prints once as Deletions stopped due to --max-delete limit (N skipped) (generator.c:2904-2907). The exit-25 trailer names the --max-delete limit stopped deletions (log.c:100).
  • Removed line. oc's max deletions reached, skipping N remaining line has no upstream counterpart and is removed.

Skip notice. IO error encountered -- skipping file deletion is printed only by a sweep that would still delete (generator.c:304-311). A --delete-before or --delete-during run's post-transfer step no longer prints it.

-x make-room.

  • Routing. peel_or_probe now takes the device-aware leaf walk whenever -x or --max-delete is in force, as the delete passes already did. A child on another device pins the obstacle, the make-room fails (23), and the mount keeps its files (delete.c:141-149, flist.c:1715).
  • Messages. A nested mount point is a DEBUG_GTE(DEL, 1) note (delete.c:144-149). Only a top-level one prints cannot delete mount point (generator.c:336-340).

Oracle, against /usr/bin/rsync 3.5.1 on Linux. Fixture: src/{a,sub/z} with an unreadable src/unread, and dst/{stale1,stale2,sub/stale3}.

Case rsync 3.5.1 oc before oc after
-ri 23, >f+++++++++ rows 23, no output 23, same rows
-r --stats 23, stats block 23, no output 23, stats block
-rv --delete-before --max-delete=1 23, files copied, (2 skipped) 25, nothing copied 23, same files, rows and (2 skipped)
-rv --delete --max-delete=1, no failure 25, rows, totals, trailer 25, rows and totals lost identical output
-rv --force -x, tmpfs inside the obstacle 23, mount file kept 23, mount file deleted identical output
-rv --delete -x, --max-delete=100, -rvv identical to the row above mount file deleted identical output

Known gaps, not in this PR:

  • Error wording. A failed source open is still reported as one rsync error: failed to copy file ... trailer, where upstream prints rsync: [sender] send_files failed to open "...": ... (13) followed by the generic some files/attrs were not transferred trailer.
  • Transfer-time failures gate deletions too early. A failure to open a source suppresses deletions decided during the walk (--delete, --delete-delay). Upstream's sender reports io_error only after its send loop (sender.c:808-809), so those decisions never see it, and upstream deletes sub/stale3 / stale2 where oc keeps them. Exit codes match; the deleted set differs. A vanished file also sets oc's gate, although upstream gates only on IOERR_GENERAL.
  • Local --stats counters. Created and transferred counts and sent/received bytes still differ from upstream on a run with an unreadable file.
  • Mount EBUSY without -x. An EBUSY rmdir of a mount reached without -x still aborts the local run. Upstream logs delete_file: rmdir(...) failed and continues.

Test plan

  • New tests fail on master and pass on this branch:
    • tests/local_copy_exit_fidelity.rs, four cases;
    • one_file_system_make_room_keeps_a_mount_inside_the_obstacle in crates/engine/src/local_copy/tests/execute_one_file_system.rs.
  • Seven mutations, each reverting one fix site, each turn at least one new test red:
    • CLI drops the summary;
    • engine drops the report;
    • limit outranks partial;
    • the pass aborts on the cap;
    • the old trailer text;
    • the unbounded -x peel;
    • the gate consulted for every timing.
  • cargo nextest run -p engine -p core -p cli -p bin --all-features: 12804 passed, 128 skipped.
  • cargo fmt --all -- --check and python3 tools/ci/check_rustfmt_all.py.
  • cargo clippy -p engine -p core -p cli -p bin --all-targets --all-features --no-deps -- -D warnings.
  • cargo check -p engine -p core -p cli --all-features --target x86_64-pc-windows-gnu.
  • python3 tools/ci/unsafe_owner_deps.py, cargo run -p xtask -- no-placeholders, cargo run -p xtask -- citations.
  • CI: fmt + clippy, nextest (stable), Windows, macOS, Linux musl.

The unreadable-file tests skip with a SKIP: line when the process can read a mode-0 file, i.e. when running as root. Repro: cargo nextest run -p bin --all-features -E 'binary(local_copy_exit_fidelity)'.

Coordination

Conventional commit prefix

fix:

Security considerations

  • Threat surface affected: local deletion under --one-file-system, and --max-delete enforcement.
  • Mitigations / tests added: the make-room peel no longer crosses a mount boundary (engine test with injected device ids, tmpfs oracle). The cap can no longer abort a transfer or be outranked silently.
  • Cross-references: delete.c:141-149, delete.c:217-219, cleanup.c:210-218.

Pre-merge checklist

  • Conventional commit prefix on PR title matches the change category.
  • cargo fmt --all run locally.
  • CHANGELOG.md updated if user-visible.
  • SECURITY.md updated if security-relevant.
  • No references to internal tooling or non-human authoring aids; hyphens, not em-dashes.

A local copy that processed every entry but owed a non-zero exit code
returned an error and the CLI dropped its summary, so an exit-23 run
printed no itemize rows, names or --stats block. The engine now attaches
the completed report to that error and the CLI renders it before the
trailer; only an aborted run has no output.

The exit code is decided once, after the run, in upstream's order
(cleanup.c:210-218): DEL_LIMIT, then VANISHED, then GENERAL or
got_xfer_error, so 23 outranks 24 outranks 25. A --max-delete cap only
counts the refusal (delete.c:217-219) and never stops the transfer;
under --delete-before it used to abort before anything was copied. The
run-wide skipped total is reported once (generator.c:2904-2907) and the
exit-25 trailer names "the --max-delete limit stopped deletions"
(log.c:100). The "max deletions reached" line, which upstream never
prints, is gone.

The "IO error encountered -- skipping file deletion" notice is printed
only by a sweep that would still delete (generator.c:304-311), not by a
--delete-before or --delete-during run's post-transfer step.
Clearing a directory obstacle for an incoming file peeled its children
with an unbounded walk that deleted straight into a mounted filesystem
under --one-file-system. The peel now takes the device-aware leaf walk
whenever -x (or --max-delete) is in force, as the delete passes do: a
child on another device pins the obstacle, the make-room fails with
exit 23, and the mount keeps every file (delete.c:141-149,
flist.c:1715). A nested mount point is a DEBUG_GTE(DEL, 1) note
(delete.c:144-149); only a top-level one prints "cannot delete mount
point" (generator.c:336-340).
The delete limit is now a run-wide skipped-deletes counter, so nothing
classifies a LocalCopyError as the limit any more.
@oferchen
oferchen merged commit c8cd64a into master Oct 20, 2026
86 checks passed
@oferchen
oferchen deleted the fix/local-copy-exit-and-output-fidelity branch October 20, 2026 17:32
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.

1 participant