Skip to content

fix: enforce --max-delete on make-room deletes and remote limits - #8218

Merged
oferchen merged 5 commits into
masterfrom
fix/max-delete-make-room
Oct 20, 2026
Merged

oferchen merged 5 commits into
masterfrom
fix/max-delete-make-room

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • --max-delete now caps the contents of a directory cleared to make room for an incoming file, locally and on a receiver. The obstacle node itself stays exempt (delete.c:217, delete.c:126), and the make-room shares one run-wide budget and one Deletions stopped warning with the delete sweeps, as upstream does.
  • A remote --max-delete=0 no longer dies with exit 12: the server clamps the forwarded --max-delete=-1 to 0 (options.c:3002-3006, options.c:2308-2311).
  • A transfer error now exits 23 even when the deletion limit (25) or a vanished file (24) also applies, matching cleanup.c:213-218.

Details

upstream exempts only the make-room removal of the obstacle node (delete.c:217, !(flags & DEL_MAKE_ROOM)). delete_dir_contents() strips that flag before it recurses (delete.c:126), so every child is an ordinary capped deletion. A child the cap refuses leaves the directory standing, the make-room fails at FERROR_XFER, and generator.c:2904-2907 reports the run-wide skipped total.

What was wrong, per commit:

  1. Server rejected the forwarded value. It parsed --max-delete as unsigned and rejected the -1 that oc and upstream clients forward for =0. Every remote --max-delete=0 transfer exited 12 before moving a file. The server now reuses the client's clamping parser.
  2. Exit codes ranked the wrong way. The exit funnel consulted got_xfer_error only for an otherwise clean run, so the deletion limit (25) beat a transfer error (23). The existing assertion (IOERR_VANISHED, got_xfer_error) -> 24 encoded that divergence and is corrected.
  3. Make-room ignored the cap.
    • Local executor: it ignored the cap. With --max-delete set, the peel now goes through the capped delete pass's leaf walk (remove_children_capped, extracted from remove_entry_capped).

    • Receiver:

      • it capped each obstacle from zero;
      • it dropped the skipped count;
      • its --delete-after sweep ignored make-room deletions;
      • it wrote the warning only on the server.

      It now keeps one run-wide skipped_deletes, settled once where generator.c:2904 does it (after the late sweep, before touch_up_dirs()). The warning is framed as MSG_WARNING, as rwrite() does (log.c:357-366).

Measured against rsync 3.5.1 with -rlI -v and dst/obstacle/{a,b} where src/obstacle is a regular file. Each cell was run locally and over a --server child. Both modes now match upstream on exit code, survivors, warning and deleting rows.

Flags rsync 3.5.1 oc before oc after
--delete --max-delete=0 23, keeps a,b, (2 skipped) local 0, cleared; remote 12 23, keeps a,b, (2 skipped)
--force --max-delete=0 23, keeps a,b, (2 skipped) local 0, cleared; remote 12 23, keeps a,b, (2 skipped)
--delete --max-delete=1 23, deletes b, keeps a, (1 skipped) local 0, cleared; remote 12 23, deletes b, keeps a, (1 skipped)
--delete --max-delete=2 0, replaced 0, replaced 0, replaced
--delete --max-delete=0, symlink obstacle 0, replaced (the node is exempt) local 0; remote 12 0, replaced
--delete --max-delete=1 plus extraneous zextra 23, zextra gone, keeps a,b, (2 skipped) not measured matches
--delete-after --max-delete=2 plus zextra 25, replaced, zextra kept, (1 skipped) not measured matches

The two zextra rows pin the shared budget in both orders: the sweep spends it first under --delete, and the make-room spends it first under --delete-after.

Mutation checks: each fix site was reverted alone and the suite turned red every time.

Mutation Red
Server parses unsigned 3 of 7
Local peel ignores the cap 4 of 7
Local warning dropped 4 of 7
Receiver skipped count dropped 4 of 7
Receiver cap restarts at 0 1 of 7
Sweep ignores make-room deletions 1 of 7
Warning kept on the server 5 of 7, plus max_delete_budget_spans_segments_and_reports_once
Old funnel precedence 4 of 7, plus io_error_rule_matches_upstream

Known gaps, not in this PR:

  • The local executor withholds every -v row of a run that ends with exit 23, with or without --max-delete. So the partial-cap cell pins the deleting obstacle/b row over the remote shell only.
  • The local executor raises a deferred delete-pass limit error (25) ahead of a partial-transfer error (23). This is the precedence of commit 2, but on the local side.
  • The uncapped local make-room peel does not preserve --one-file-system mount points the way delete_dir_contents()'s FLAG_MOUNT_DIR check does.

Test plan

  • CI: fmt + clippy, nextest (stable), Windows, macOS, Linux musl.
  • cargo fmt --all -- --check and python3 tools/ci/check_rustfmt_all.py
  • cargo clippy -p transfer -p engine -p core -p cli -p bin --all-targets --all-features --no-deps -- -D warnings
  • cargo nextest run -p transfer -p engine -p core -p cli --all-features (15271 passed)
  • cargo nextest run -p bin --all-features -E 'binary(make_room_max_delete)' (7 passed), plus the 16 root binaries touching delete, obstacle, max-delete and exit codes (121 passed)
  • cargo run --locked -p xtask -- no-placeholders, cargo run --locked -p xtask -- citations, python3 tools/ci/citation_drift_audit.py --ratchet, python3 tools/ci/unsafe_owner_deps.py
  • Oracle: the cells in Details run against /usr/bin/rsync 3.5.1 (protocol 33), locally and over a --rsh shim, compared on exit code, surviving files and stderr

Coordination

  • Related PRs / issues: none open.
  • Depends on: none.
  • Blocked by: none.
  • The exit-code funnel change touches crates/core/src/exit_code/funnel.rs, which no other open PR touches.

Conventional commit prefix

fix:

Security considerations

  • Threat surface affected: --max-delete is a data-safety control. Before this change, a make-room peel could remove an unbounded number of files despite the cap (locally, and on the receiver when earlier deletions had used up the budget).
  • Mitigations / tests added: every make-room child now counts against the run-wide cap before removal. tests/make_room_max_delete.rs pins the refusal, the partial cap, the exempt single-entry node and the shared budget, locally and over a remote shell, and is mutation-checked.
  • Cross-references: delete.c:126, delete.c:217-218, generator.c:2904-2907, cleanup.c:213-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 client asked for --max-delete=0 forwards --max-delete=-1
(options.c:3002-3006), and upstream clamps any negative value back to 0
(options.c:2308-2311). The server parsed the value as unsigned and refused
it, so every remote --max-delete=0 transfer died with exit 12 before a
single file moved. Reuse the client parser, which already clamps.
cleanup.c:213-218 assigns RERR_PARTIAL last, for io_error & IOERR_GENERAL
or got_xfer_error, so a transfer error outranks RERR_VANISHED and
RERR_DEL_LIMIT too. The funnel consulted got_xfer_error only for an
otherwise clean run, so a refused make-room that also tripped
--max-delete exited 25 where rsync 3.5.1 exits 23.
delete_dir_contents() strips DEL_MAKE_ROOM before it recurses
(delete.c:126), so every child of a directory cleared to make room is an
ordinary capped deletion (delete.c:217), while the obstacle node itself
stays exempt. A child the cap refuses leaves the directory standing, the
make-room fails at FERROR_XFER, and generator.c:2904-2907 reports the
skipped total.

The local executor ignored the cap entirely and cleared the obstacle at
exit 0. The receiver capped each obstacle from zero, dropped the skipped
count, sized a --delete-after sweep without the make-room deletions, and
reported the limit only on the server side. Both now share upstream's
single run-wide budget and skipped_deletes, and the receiver frames the
warning for the client as MSG_WARNING like rwrite() does.
@oferchen
oferchen merged commit 22a42b0 into master Oct 20, 2026
86 checks passed
@oferchen
oferchen deleted the fix/max-delete-make-room branch October 20, 2026 14:01
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