Skip to content

fix: alt-dest --copy-dest symlink resolution via remote shell - #5525

Merged
oferchen merged 2 commits into
masterfrom
fix/uts-2-alt-dest-remote-shell-symlinks
Jun 10, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/uts-2-alt-dest-remote-shell-symlinks

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

Upstream try_dests_reg (generator.c:942) probes each basis-dir
candidate with link_stat(cmpbuf, &sxp->st, 0) (generator.c:953),
which dispatches to x_lstat() by default and x_stat() only when
copy_links is set (flist.c:234). The follow-up !S_ISREG check
filters out basis-dir entries that are themselves symlinks.

The receiver's try_reference_dest instead stat'd basis-dir entries
with fs::metadata() (always follows symlinks) and accepted any
entry whose followed-stat reported a regular file. When the
basis-dir entry was a symlink, oc-rsync silently copied or
hard-linked from the symlink's target, while upstream would have
skipped the basis-dir entry and requested a wire transfer instead.
Under remote-shell transports the divergence shows up on the
alt-dest.test lsh.sh sub-tests (UTS-2 / #3560).

Fix

  • crates/transfer/src/receiver/quick_check.rs — try_reference_dest
    now takes a copy_links argument. When copy_links is false the
    basis-dir entry is stat'd with fs::symlink_metadata() (lstat),
    matching upstream's x_lstat() path. When copy_links is true the
    call falls through to fs::metadata(), matching upstream's
    x_stat() follow path. The accept gate is now
    file_type().is_file() on the un-followed metadata, which mirrors
    upstream's S_ISREG(sxp->st.st_mode) check.
  • crates/transfer/src/receiver/transfer/candidates.rs — pass
    self.config.flags.copy_links through to try_reference_dest.

Tests

  • crates/transfer/src/receiver/quick_check.rs::symlink_basis_tests
    • copy_dest_skips_symlink_basis_entry_without_copy_links
    • link_dest_skips_symlink_basis_entry_without_copy_links
    • compare_dest_skips_symlink_basis_entry_without_copy_links
    • copy_dest_follows_symlink_basis_entry_with_copy_links
    • copy_dest_matches_regular_basis_entry_without_copy_links

Each test builds a basis-dir whose entry for the source name is a
symlink to a regular file with matching size, then verifies that
try_reference_dest returns false (no local handling) under the
default copy_links=false, and true only when copy_links=true.
The regular-file baseline guards against an over-eager fix that
breaks the common case.

Test plan

  • Unit tests added for copy-dest, link-dest, compare-dest with
    symlink basis under copy_links=false.
  • Unit test added for copy_links=true follow path.
  • Regular-file basis-dir baseline preserved.
  • CI: required interop matrix.
  • CI: fmt+clippy, nextest (stable), Windows, macOS, Linux musl.

The receiver's `try_reference_dest` stat'd basis-dir entries with
`fs::metadata()` (follows symlinks), then accepted any entry whose
followed-stat reported a regular file. Upstream `try_dests_reg`
(generator.c:953) uses `link_stat(cmpbuf, &sxp->st, 0)`, which calls
`x_lstat()` by default (flist.c:234) and filters with `!S_ISREG`. The
follow-through to `x_stat()` only happens when `copy_links` is set.

A basis-dir entry that is itself a symlink was therefore silently
consumed by `--copy-dest` / `--link-dest` / `--compare-dest` even when
upstream would skip it. Under remote-shell transports this caused the
receiver to populate the destination locally for a file the sender
expected to deliver, diverging from upstream's wire pattern on the
`alt-dest.test` lsh.sh sub-tests.

Plumb `copy_links` through to `try_reference_dest` and stat the
basis-dir entry with `symlink_metadata` when `copy_links` is off,
falling back to follow-stat when `-L` is set. Add regression coverage
for copy-dest, link-dest, and compare-dest under a symlink basis, plus
the copy_links=true follow path and a regular-file baseline.
@github-actions github-actions Bot added the bug Something isn't working label Jun 10, 2026
oferchen added a commit that referenced this pull request Jun 10, 2026
Group PRs #5510, #5516, #5519, #5520, #5523, #5525-#5544 by shared root
cause rather than by Stream bucket. Seven clusters surface; the parser-
stores-string and field-vs-method shadowing clusters cover the largest
share of the series, and the receiver-driver wiring-parity gap explains
the NDX_DEL_STATS goodbye misses in both #5536 and #5542. Includes a
defense-in-depth audit mapping each cluster onto the rust-landlock
ruleset wired at crates/fast_io/src/landlock.rs.

Doc-only; no code paths touched.
oferchen added a commit that referenced this pull request Jun 10, 2026
Group PRs #5510, #5516, #5519, #5520, #5523, #5525-#5544 by shared root
cause rather than by Stream bucket. Seven clusters surface; the parser-
stores-string and field-vs-method shadowing clusters cover the largest
share of the series, and the receiver-driver wiring-parity gap explains
the NDX_DEL_STATS goodbye misses in both #5536 and #5542. Includes a
defense-in-depth audit mapping each cluster onto the rust-landlock
ruleset wired at crates/fast_io/src/landlock.rs.

Doc-only; no code paths touched.
@oferchen
oferchen merged commit be4928f into master Jun 10, 2026
68 checks passed
@oferchen
oferchen deleted the fix/uts-2-alt-dest-remote-shell-symlinks branch June 10, 2026 10:03
oferchen added a commit that referenced this pull request Aug 24, 2026
Group PRs #5510, #5516, #5519, #5520, #5523, #5525-#5544 by shared root
cause rather than by Stream bucket. Seven clusters surface; the parser-
stores-string and field-vs-method shadowing clusters cover the largest
share of the series, and the receiver-driver wiring-parity gap explains
the NDX_DEL_STATS goodbye misses in both #5536 and #5542. Includes a
defense-in-depth audit mapping each cluster onto the rust-landlock
ruleset wired at crates/fast_io/src/landlock.rs.

Doc-only; no code paths touched.
oferchen added a commit that referenced this pull request Aug 24, 2026
* fix: alt-dest --copy-dest symlink resolution via remote shell

The receiver's `try_reference_dest` stat'd basis-dir entries with
`fs::metadata()` (follows symlinks), then accepted any entry whose
followed-stat reported a regular file. Upstream `try_dests_reg`
(generator.c:953) uses `link_stat(cmpbuf, &sxp->st, 0)`, which calls
`x_lstat()` by default (flist.c:234) and filters with `!S_ISREG`. The
follow-through to `x_stat()` only happens when `copy_links` is set.

A basis-dir entry that is itself a symlink was therefore silently
consumed by `--copy-dest` / `--link-dest` / `--compare-dest` even when
upstream would skip it. Under remote-shell transports this caused the
receiver to populate the destination locally for a file the sender
expected to deliver, diverging from upstream's wire pattern on the
`alt-dest.test` lsh.sh sub-tests.

Plumb `copy_links` through to `try_reference_dest` and stat the
basis-dir entry with `symlink_metadata` when `copy_links` is off,
falling back to follow-stat when `-L` is set. Add regression coverage
for copy-dest, link-dest, and compare-dest under a symlink basis, plus
the copy_links=true follow path and a regular-file baseline.

* style: rustfmt quick_check.rs reference test helper
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