Skip to content

fix(transfer): carry the pre-image's identity onto a copied backup - #7622

Merged
oferchen merged 2 commits into
masterfrom
fix/backup-copy-tier-metadata
Sep 2, 2026
Merged

oferchen merged 2 commits into
masterfrom
fix/backup-copy-tier-metadata

Conversation

@oferchen

@oferchen oferchen commented Sep 2, 2026

Copy link
Copy Markdown
Owner

The upstream rule

make_backup_inner is a three-tier ladder. Only the copy tier needs explicit
metadata handling, and upstream says so by construction — set_file_attrs is
reached only from the copy_file() arm:

/* backup.c:398-421, the copy tier's tail */
if (!ret) {
    if (copy_file(fname, buf, -1, file->mode) < 0) { ... return 0; }
    ret = 2;
}
save_preserve_xattrs = preserve_xattrs;
preserve_xattrs = 0;
set_file_attrs(buf, file, NULL, fname, ATTRS_ACCURATE_TIME);   /* :420 */
preserve_xattrs = save_preserve_xattrs;

The hardlink (backup.c:239-246) and rename tiers move or share the inode, so
owner, 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/transfer had no analogue:

site before
backup_rename_or_copy EXDEV fallback (commit.rs:531) bare fs::copy + remove_file
make_backup_copy (--inplace --backup, commit.rs:964) copy → BackupNotice, nothing between

fs::copy carries content and permission bits. On a cross-device
--backup-dir the backup therefore kept the right bytes and mode and silently
lost 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 delegates
to metadata::apply_file_metadata_with_options, the same call the engine sites
and the backup-parent helper (apply_backup_dir_attrs) already make — no new
mechanism.

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 apply is confined — metadata::apply issues
fast_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_copy the read is an fstat on the descriptor
copy_pre_image_to_backup already holds open, which is the property
3.5.0's backup_source_fd exists to provide — a parent-symlink flip cannot
redirect it.

Non-vacuity, and an honest platform limit

cross_device_backup_carries_the_pre_image_timestamps asserts the backup keeps
the 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::copy there routes through fclonefileat/fcopyfile, which clone
the 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::copy drops 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::copy and fails if a
platform 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, not
measured here — the Linux host was unreachable. CI's Linux cells exercise it.

Verification

  • cargo nextest run -p transfer --lib — 2429/2429.
  • cargo fmt --all -- --check clean.
  • Mutation: removing the EXDEV apply leaves the cell green on macOS only,
    which is the measurement reported above rather than a passed mutation gate.
  • Clippy: -p transfer --all-targets reports 81 errors on this branch and
    81 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 zeroes preserve_xattrs around that very call, so
xattrs are cached but not applied at this site, and oc has no cache analogue
(task 1088). This change covers exactly what set_file_attrs applies there:
owner, group, times and mode.

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.
@github-actions github-actions Bot added the bug Something isn't working label Sep 2, 2026
…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
oferchen merged commit b9c0b69 into master Sep 2, 2026
73 checks passed
@oferchen
oferchen deleted the fix/backup-copy-tier-metadata branch September 2, 2026 15:26
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.
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