Skip to content

fix(cli): only report is_local_sender for remote-dest pushes - #5798

Merged
oferchen merged 4 commits into
masterfrom
fix/itemize-local-copy-direction
Jun 15, 2026
Merged

oferchen merged 4 commits into
masterfrom
fix/itemize-local-copy-direction

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

  • PR fix(cli): pass is_sender from ClientConfig into OutFormatContext #5794 added ClientConfig::is_local_sender() to thread the itemize direction arrow into OutFormatContext. The docstring claimed the local-copy/empty-args polarity was harmless because "upstream hits the local_server branch which emits `>`". That assumption holds for upstream's log.c, but oc-rsync's itemize formatter at frontend/out_format/render/itemize.rs only branches on is_sender — it does not model local_server — so the helper returning `true` for local copies made the formatter emit `<` where upstream emits `>`.
  • Three tests broke across every Linux/macOS/Windows nextest cell on master HEAD b13be109:
    • itemize_combined_with_dry_run_shows_what_would_transfer
    • itemize_combined_with_verbose_shows_itemized_format
    • itemize_last_toggle_wins_enabled
  • Narrowed is_local_sender() so it returns `true` only when the destination is remote and every source is local — the exact case upstream's log.c:701-704 renders as `<`. Local copies, pulls, empty arg lists, and proxy operations now return `false` so the formatter emits `>` to match upstream.
  • Updated the two stale unit tests (is_local_sender_local_copy_reports_*, is_local_sender_empty_args_reports_*) that expected the old polarity.

upstream: log.c:701-704 — !local_server && *op == 's' ? '<' : '>'

Test plan

  • nextest (stable) — itemize_combined_with_dry_run_shows_what_would_transfer passes
  • nextest (stable) — itemize_combined_with_verbose_shows_itemized_format passes
  • nextest (stable) — itemize_last_toggle_wins_enabled passes
  • nextest (stable) — is_local_sender_push_reports_sender still passes
  • nextest (stable) — is_local_sender_pull_reports_receiver still passes
  • nextest (stable) — is_local_sender_double_colon_push_reports_sender still passes
  • fmt+clippy green
  • Windows + macOS + Linux musl nextest cells green

oferchen added 3 commits June 15, 2026 01:27
Under the lsh.sh remote-shell transport (00-hello, alt-dest, files-from,
ssh-basic, symlink-dirlink-basis, hardlinks), the previous receiver-only
stdin drain caused the server-sender (generator) process to exit before
the upstream peer (running as server-receiver child) finished its
exit_cleanup() sequence in noop_io_until_death(). The peer was left
waiting for FIN on its stdin while we tore down, producing
"connection unexpectedly closed" and a 300s timeout in runtests.py.

Upstream cleanup.c:254 calls noop_io_until_death() unconditionally for
both am_sender and am_receiver server children; mirror that contract by
removing the role gate so the generator path also drains stdin to EOF
after shutting down its write half.

upstream: io.c:943 noop_io_until_death(), cleanup.c:254 _exit_cleanup()
Extract the previously-inlined stdin drain loop into a `Read`-generic
helper and add nextest coverage for the four shapes that matter on the
lsh.sh / SSH transport:

- bare EOF (the steady-state case once the peer's exit_cleanup runs)
- payload-then-EOF (peer flushes trailing MSG_STATS / NDX_DONE before FIN)
- Interrupted + WouldBlock retries (no spurious exit on transient errors)
- hard error (drain breaks cleanly instead of spinning)

The helper mirrors upstream rsync's noop_io_until_death() (io.c:943) and
is now exercised by both the receiver and the generator roles after the
goodbye handshake. Tests document the contract so a future revert of the
gate would surface immediately.
PR #5794 added ClientConfig::is_local_sender() to thread the itemize
direction arrow into OutFormatContext. Its docstring claimed the
local-copy and empty-args polarity was "harmless because upstream hits
the local_server branch which emits >". That assumption holds for
upstream's log.c, but oc-rsync's itemize formatter at
frontend/out_format/render/itemize.rs only branches on is_sender. With
the helper returning true for local copies the formatter started
emitting < where upstream emits >, breaking every local-copy itemize
test (itemize_combined_with_dry_run_shows_what_would_transfer,
itemize_combined_with_verbose_shows_itemized_format,
itemize_last_toggle_wins_enabled) across all platforms.

Narrow is_local_sender() to return true only when the destination is
remote and every source is local - the exact case upstream's log.c
renders as <. Local copies, pulls, empty arg lists, and proxy
operations all return false so the formatter emits > to match upstream.

upstream: log.c:701-704
@github-actions github-actions Bot added the bug Something isn't working label Jun 15, 2026
PR #5793 added `chmod_path_honoring_keep_dirlinks` but only routed the
chmod-modifier and compute_dest_mode paths through it. The path-based
fallbacks in `set_permissions_like`, `apply_permissions_without_chmod`
executability branch, and both `apply_permissions_from_entry` branches
still called `fast_io::secure_chmod_at` directly, which the dirfd
sandbox refuses when the destination's parent is a symlink-to-a-dir.

Failing test `apply::tests::keep_dirlinks_bypasses_secure_chmod_sandbox`
on every Unix CI cell exercised the `apply_file_metadata_with_options`
-> `apply_permissions_without_chmod` -> `set_permissions_like` chain
and hit ENOTDIR on `dest/alpha/a.txt` whose parent `alpha` is a symlink.

Route all four remaining sites through the helper. Pass `options` into
`set_permissions_like` (only 2 callers, both in this file) so the Unix
chmod can pick `std::fs::set_permissions` when `keep_dirlinks` is set,
mirroring upstream `generator.c:1344 link_stat(fname, &sx.st,
keep_dirlinks && is_dir)`.
@oferchen
oferchen merged commit d4b7c1e into master Jun 15, 2026
116 of 120 checks passed
oferchen added a commit that referenced this pull request Jun 15, 2026
#5803)

Add a cross-platform regression test asserting that
apply_file_metadata_with_options succeeds through a symlinked destination
directory under --keep-dirlinks on Linux, macOS, and Windows. Pins the
guarantee from PR #5793 (macOS chmod bypass) and PRs #5798/#5799
(extension to four more chmod sites), and codifies that Linux
(openat2 RESOLVE_BENEATH sandboxes parents only) and Windows (chmod
no-op) are clean by construction.
@oferchen
oferchen deleted the fix/itemize-local-copy-direction branch June 15, 2026 10:42
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix(cli): drain stdin for both server roles to unblock peer shutdown

Under the lsh.sh remote-shell transport (00-hello, alt-dest, files-from,
ssh-basic, symlink-dirlink-basis, hardlinks), the previous receiver-only
stdin drain caused the server-sender (generator) process to exit before
the upstream peer (running as server-receiver child) finished its
exit_cleanup() sequence in noop_io_until_death(). The peer was left
waiting for FIN on its stdin while we tore down, producing
"connection unexpectedly closed" and a 300s timeout in runtests.py.

Upstream cleanup.c:254 calls noop_io_until_death() unconditionally for
both am_sender and am_receiver server children; mirror that contract by
removing the role gate so the generator path also drains stdin to EOF
after shutting down its write half.

upstream: io.c:943 noop_io_until_death(), cleanup.c:254 _exit_cleanup()

* test(cli): drain_stdin_until_eof unit tests for server-sender shutdown

Extract the previously-inlined stdin drain loop into a `Read`-generic
helper and add nextest coverage for the four shapes that matter on the
lsh.sh / SSH transport:

- bare EOF (the steady-state case once the peer's exit_cleanup runs)
- payload-then-EOF (peer flushes trailing MSG_STATS / NDX_DONE before FIN)
- Interrupted + WouldBlock retries (no spurious exit on transient errors)
- hard error (drain breaks cleanly instead of spinning)

The helper mirrors upstream rsync's noop_io_until_death() (io.c:943) and
is now exercised by both the receiver and the generator roles after the
goodbye handshake. Tests document the contract so a future revert of the
gate would surface immediately.

* fix(cli): only report is_local_sender for remote-dest pushes

PR #5794 added ClientConfig::is_local_sender() to thread the itemize
direction arrow into OutFormatContext. Its docstring claimed the
local-copy and empty-args polarity was "harmless because upstream hits
the local_server branch which emits >". That assumption holds for
upstream's log.c, but oc-rsync's itemize formatter at
frontend/out_format/render/itemize.rs only branches on is_sender. With
the helper returning true for local copies the formatter started
emitting < where upstream emits >, breaking every local-copy itemize
test (itemize_combined_with_dry_run_shows_what_would_transfer,
itemize_combined_with_verbose_shows_itemized_format,
itemize_last_toggle_wins_enabled) across all platforms.

Narrow is_local_sender() to return true only when the destination is
remote and every source is local - the exact case upstream's log.c
renders as <. Local copies, pulls, empty arg lists, and proxy
operations all return false so the formatter emits > to match upstream.

upstream: log.c:701-704

* fix(metadata): cover remaining chmod sites under --keep-dirlinks bypass

PR #5793 added `chmod_path_honoring_keep_dirlinks` but only routed the
chmod-modifier and compute_dest_mode paths through it. The path-based
fallbacks in `set_permissions_like`, `apply_permissions_without_chmod`
executability branch, and both `apply_permissions_from_entry` branches
still called `fast_io::secure_chmod_at` directly, which the dirfd
sandbox refuses when the destination's parent is a symlink-to-a-dir.

Failing test `apply::tests::keep_dirlinks_bypasses_secure_chmod_sandbox`
on every Unix CI cell exercised the `apply_file_metadata_with_options`
-> `apply_permissions_without_chmod` -> `set_permissions_like` chain
and hit ENOTDIR on `dest/alpha/a.txt` whose parent `alpha` is a symlink.

Route all four remaining sites through the helper. Pass `options` into
`set_permissions_like` (only 2 callers, both in this file) so the Unix
chmod can pick `std::fs::set_permissions` when `keep_dirlinks` is set,
mirroring upstream `generator.c:1344 link_stat(fname, &sx.st,
keep_dirlinks && is_dir)`.
oferchen added a commit that referenced this pull request Aug 24, 2026
#5803)

Add a cross-platform regression test asserting that
apply_file_metadata_with_options succeeds through a symlinked destination
directory under --keep-dirlinks on Linux, macOS, and Windows. Pins the
guarantee from PR #5793 (macOS chmod bypass) and PRs #5798/#5799
(extension to four more chmod sites), and codifies that Linux
(openat2 RESOLVE_BENEATH sandboxes parents only) and Windows (chmod
no-op) are clean by construction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant