Repository navigation
fix(transfer): carry the pre-image's identity onto a copied backup - #7622
Merged
Merged
Conversation
The backup ladder has three tiers. Hardlink and rename move or share the
inode, so ownership, timestamps and mode travel with it for free. The copy
tier builds a new inode and carries none of that, which is why upstream
applies the attributes explicitly on that branch alone:
set_file_attrs(buf, file, NULL, fname, ATTRS_ACCURATE_TIME);
at backup.c:420, reached only from the copy_file() arm at backup.c:400.
The transfer crate had no analogue at either of its copy sites:
- backup_rename_or_copy's cross-device (EXDEV) fallback was a bare
fs::copy + remove_file, so a --backup-dir on another mount produced a
backup with the right bytes and mode but the wrong owner, group and
timestamps.
- make_backup_copy (the --inplace --backup path) went straight from
copy_pre_image_to_backup to the BackupNotice.
Both now route through one owner, apply_copied_backup_metadata, which
delegates to metadata::apply_file_metadata_with_options - the same call the
engine's local-copy backup sites and the backup-parent helper already make.
Best-effort, like upstream: set_file_attrs reports and continues, so a
backup that cannot take the owner (the ordinary non-root case) is still a
valid backup.
The source is stat'd BEFORE the copy at both sites. The cross-device tier
unlinks the pre-image once the duplicate is in place, so a stat afterwards
would find nothing.
Scope note: the engine's local-copy backup paths were already correct - they
reapply full metadata right after their copy. The gap was transfer-only,
which is why "does oc apply backup metadata?" answered yes on inspection.
The new cell carries its own non-vacuity control. On Linux a bare fs::copy
drops the timestamp, so the assertion is lethal; on macOS fs::copy routes
through fclonefileat/fcopyfile and clones the metadata, which was MEASURED -
with the apply removed the cell still passes there. The control asserts that
any platform where a bare copy preserves mtime is macOS, so a new platform
silently making the cell vacuous fails loudly instead of going green.
…OS list The non-vacuity guard on the cross-device backup cell fired on Windows. It was right to: `std::fs::copy` there goes through `CopyFileExW`, which copies the source timestamps, so the mtime observable cannot tell the metadata apply from its absence on that platform any more than it can on macOS. The defect was the guard's shape. It named macOS as the one known copy-preserving platform and asserted one direction only, so it could catch a platform that STARTS preserving the timestamp but passed silently if one stopped - and its list was a guess about platforms rather than a measurement. Assert the probe against the expected set instead. Both directions now fail loudly, and the message says to re-derive the set by measuring the new platform rather than widening it to make the cell pass. The discriminating assertion is unchanged and still runs everywhere; it stays lethal on Linux, where a bare copy carries bytes and permission bits only, and is a reversion guard on macOS and Windows.
oferchen
added a commit
that referenced
this pull request
Sep 2, 2026
… merged PRs (#7634) * docs(rustdoc): reach the public items rustdoc could not see, and gate the class Two halves of the same question - is what a public item says actually reachable from `cargo doc`? Half 1: seven `//` comment blocks documented a `pub` item, so their text never reached the generated docs. Found positionally, not by content: a `//` run whose next non-attribute line declares a `pub` item. A census keyed on comment CONTENT is false-positive dominated; this one is mechanical. Nine sites matched; two are DELIBERATELY left as `//`, because they document the `#[cfg_attr]` / `#[allow]` attribute directly beneath them rather than the item - `local_copy/overrides.rs` and `local_copy/plan/report.rs`. Promoting those would attach a lint rationale to a public surface as if it described the surface. Text is preserved verbatim, upstream citations included (`generator.c:2149` on the obstacle module). The only rewrite is `socket_options/consts.rs`, where one group note covered two constants: split per item, matching the file's own house style where every other const already carries `///`. Half 2: five intra-doc links could not resolve in a DEFAULT build, and the existing gate is structurally unable to see them. crates/fast_io/src/lib.rs, ewma.rs (x4) -> `adaptive_dispatch`, gated by the off-by-default `adaptive-basis-dispatch` feature crates/rsync_io/.../sync_bridge.rs -> `crate::channel_adapter`, gated by the off-by-default `async-ssh` feature crates/fast_io/src/confinement.rs -> `PinnedRoot`, a PRIVATE struct plus one already on the branch in `module_list/types.rs`, where the link was `Transport::Quic` (the `quic` feature) and its surrounding prose still described the variant as unbuilt. Every crate denies `rustdoc::broken_intra_doc_links`, so each of these is a hard `cargo doc` failure, not a warning. MEASURED on the pristine base: cargo doc --no-deps --workspace -> 7 errors, `fast_io` and `rsync_io` could not be documented cargo doc --no-deps --workspace --all-features -> clean That gap is the whole point. Under `--all-features` the gated items EXIST, so the link resolves and the gate is green; in a default build the item is not compiled at all. `ci.yml`'s `rustdoc-links` job runs only `--all-features`, deliberately mirroring `pages.yml` - which is right for the question Pages asks and cannot ask this one. So the fix is paired with a SECOND step on default features, and neither subsumes the other: `crates/fast_io/src/io_uring` is `cfg(all(target_os = "linux", feature = "io_uring"))` and only the all-features run compiles it. The names stay in backticks with the reason stated at each site, rather than being deleted or the links made conditional - the prose still says what it said, and the next reader learns why it is not a link. After: both invocations document all 25 crates cleanly, 0 errors. fmt clean; clippy on the five touched crates reports no new diagnostics. * docs(changelog): record the ten pull requests merged since the last sweep #7624 brought the Unreleased section up to #7620 and then stopped being true: #7621-#7632 landed after it, of which #7624 is itself that changelog pass and #7628 was never merged. Ten entries were missing. Each is placed in the subsection its change belongs to rather than appended in number order, and #7625 is SPLIT across two, because it is two changes: wiring `--force` is a receiver fix, and the synthetic-transfer-root guard that wiring made necessary is a peer-supplied input bound. Filing it once under either heading would have hidden whichever half the reader was looking for. Security / peer-supplied input bounds #7625 (guard half), #7630 Fixed / transfer and receiver #7622, #7625 (--force half), #7627 Fixed / daemon #7629 Testing and CI #7621, #7623, #7632 Documentation #7626, #7631 Wording is taken from each merge commit's own body, not from its title - the titles compress away the part a reader needs. #7629's title says "keep a dead name converter apart from an unknown name"; what makes it worth an entry is that five outcomes collapsed into one `None` and the merge failed OPEN on exactly the mechanism an operator installs to take ownership decisions away from the peer.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The upstream rule
make_backup_inneris a three-tier ladder. Only the copy tier needs explicitmetadata handling, and upstream says so by construction —
set_file_attrsisreached only from the
copy_file()arm:The hardlink (
backup.c:239-246) and rename tiers move or share the inode, soowner, group, times and mode travel with it. The copy tier builds a new inode
and carries none of it.
The gap
Two sites in
crates/transferhad no analogue:backup_rename_or_copyEXDEV fallback (commit.rs:531)fs::copy+remove_filemake_backup_copy(--inplace --backup,commit.rs:964)BackupNotice, nothing betweenfs::copycarries content and permission bits. On a cross-device--backup-dirthe backup therefore kept the right bytes and mode and silentlylost owner, group and both timestamps.
Scope correction worth stating
The engine's local-copy backup sites were already correct — both reapply
full metadata immediately after their copy, one of them citing
generator.c:1988. The gap was transfer-only. That is why the obvious check —"does oc apply backup metadata?" — answers yes on inspection and misses this.
The fix
One owner,
apply_copied_backup_metadata, called from both sites. It delegatesto
metadata::apply_file_metadata_with_options, the same call the engine sitesand the backup-parent helper (
apply_backup_dir_attrs) already make — no newmechanism.
Best-effort, like upstream:
set_file_attrsreports and continues, so a backupthat cannot take the owner (the ordinary non-root case) is still a valid backup.
The apply is confined —
metadata::applyissuesfast_io::secure_{chmod,chown,utimes}_at, which re-resolve the parent per call,so nothing re-opens the backup path with libc resolution.
The source is stat'd before the copy at both sites: the cross-device tier
unlinks the pre-image once the duplicate is in place, so a stat afterwards would
find nothing. In
make_backup_copythe read is anfstaton the descriptorcopy_pre_image_to_backupalready holds open, which is the property3.5.0's
backup_source_fdexists to provide — a parent-symlink flip cannotredirect it.
Non-vacuity, and an honest platform limit
cross_device_backup_carries_the_pre_image_timestampsasserts the backup keepsthe pre-image's mtime. mtime is the discriminator rather than ownership because
a non-root test process cannot
chown.Measured, not assumed: with the apply removed, this cell still passes on
macOS —
fs::copythere routes throughfclonefileat/fcopyfile, which clonethe metadata. So on macOS the copy tier is accidentally correct for every
attribute a non-root process can observe, and this cell is a reversion guard.
On Linux
fs::copydrops the timestamp and the assertion is lethal.Rather than ship a silently-vacuous cell, the test carries that as an asserted
control: it runs the same fixture through a bare
fs::copyand fails if aplatform preserves mtime and is not macOS. A new platform making the cell
vacuous fails loudly instead of going green.
⚠ The Linux leg of that claim is reasoned from
std's implementation, notmeasured here — the Linux host was unreachable. CI's Linux cells exercise it.
Verification
cargo nextest run -p transfer --lib— 2429/2429.cargo fmt --all -- --checkclean.which is the measurement reported above rather than a passed mutation gate.
-p transfer --all-targetsreports 81 errors on this branch and81 on the pristine base under the local 1.94 toolchain — identical, so
none are introduced here.
Deliberately not in scope: the ACL/xattr cache (
cache_tmp_acl/backup_source_fd). Upstream zeroespreserve_xattrsaround that very call, soxattrs are cached but not applied at this site, and oc has no cache analogue
(task 1088). This change covers exactly what
set_file_attrsapplies there:owner, group, times and mode.