Skip to content

fix: read local ACL and xattrs once, before the delete pass - #8332

Merged
oferchen merged 13 commits into
masterfrom
fix/local-acl-xattr-read-once
Nov 11, 2026
Merged

oferchen merged 13 commits into
masterfrom
fix/local-acl-xattr-read-once

Conversation

@oferchen

@oferchen oferchen commented Nov 4, 2026 •

Copy link
Copy Markdown
Owner

fix: read local ACL and xattrs once, before the delete pass

Task 520. Builds on #8288 (merged).

Problem

A local copy read each entry's ACL and xattrs at apply time, after the directory's --delete sweep had already run. When a source entry's xattrs could not be read, oc reported the failure but had already deleted in that directory. 3.5.1 reads them while building the file list (flist.c:2050-2087 send_file_name: get_acl, then get_xattr). A failure sets io_error |= IOERR_GENERAL and drops the entry, so the generator's delete_in_dir prints "IO error encountered -- skipping file deletion" and deletes nothing. oc's divergence was data loss: an extraneous destination file was removed where 3.5.1 keeps it.

Change

  • The directory planner (plan_directory_entries*, the flist-build analogue) reads each entry's ACL and xattrs once. A read failure records the flist I/O error and drops the entry, the same path as the existing iconv drop. So --delete sees the error before it runs.
  • The values ride on PlannedEntry.attrs into CopyContext.entry_attrs at dispatch. Every consumer reads that slot instead of re-reading the source: xattr apply, ACL apply (Linux LocalAcls::apply), the itemize x bit, batch capture and --delay-updates (DeferredUpdate.source_attrs). A directory frame takes its own attrs at frame start; operands are read in handlers.rs.
  • metadata: sync_xattrs_from_list (list-driven apply plus prune_unretained) and a fallible LocalAcls::read whose error names the ACL type, matching acls.c:752-755 (get_acl: sys_acl_get_file(%s, %s)).
  • -LX: the local sender reads xattrs without following links, which mirrors 3.5.1's sys_llistxattr/sys_lgetxattr (xattrs.c:162,200). ACLs still follow, as sys_acl_get_file does. When an unsafe operand symlink is dereferenced, copy_symlink re-reads the referent's attrs.

Read count (strace, 100 files, source-path calls only, base = #8288 as merged, head 2c3bb6f)

run base this PR
-rX listxattr 201, getxattr 200 listxattr 101, getxattr 100
-rX --write-batch listxattr 302, getxattr 300 listxattr 101, getxattr 100
-rA ACL getxattr 102 102
-rA --write-batch ACL getxattr 204 102

Each entry is read once: 2 reads down to 1 under -X, and 3 down to 1 with --write-batch. -rA was already at one read; -rA --write-batch drops from 2 to 1.

Tests

  • tests/local_xattr_read_failure.rs: each cell runs against 3.5.1 and oc. The headline cell is local_delete_is_skipped_after_an_unreadable_xattr, which keeps the extraneous file and prints "IO error encountered -- skipping file deletion" with exit 23. The other cells cover the dropped file, the dry run and the dropped operand.
  • tests/local_attrs_parity.rs: oc vs 3.5.1 for xattrs landing, itemize drift, xattr prune on an in-place directory update, and ACLs landing.
  • Mutations: 13 of 13 killed (N1-N13). They cover each consumer losing the slot, the planner not dropping, the delete gate, the prune and the link-follow flag.
  • Gates: rustfmt-all, workspace clippy, clippy windows-gnu, no-default engine/metadata clippy (none, xattr, acl), dead-code census. nextest: protocol, engine, batch, transfer, metadata, core, cli and the bin attrs/batch cells all pass. Interop oracle: 688 cells, 662 pass, 26 XFAIL, 0 fail.

Known limits

  • Windows: the ADS/DACL path is left out. Windows still reads at apply time.
  • macOS and FreeBSD ACLs are still read at apply time (sync_acls_if_requested). Only Linux takes the ACL from the planner slot. The xattr read moves on every platform.
  • 3.5.1 cannot reliably replay a batch whose new directory carries xattrs: its forked receiver/generator race fails with "stat ... failed", exit 23. Directory-xattr batch cells replay with oc only (see fix: carry xattrs in local batches and drop unreadable-xattr entries #8288).
  • The ACL read-failure path has no cell: making sys_acl_get_file fail needs root (or a filesystem that refuses it) on the runner. The xattr failure is covered as non-root.

Folded in: local-copy residuals (task 540)

Three divergences found while building the change above, each checked against the 3.5.1 tarball build.

--fake-super -A ACL stashes

--fake-super sets the global am_root = -1 (options.c:672) and is never passed to the server. So in a local copy the sender runs fake-super too, and so does the client side of a push. That sender reads only the %aacl/%dacl stash: get_rsync_acl() returns early when get_xattr_acl() finds none (acls.c:599-607). The ACL stays the empty one get_acl_fdat() started with (acls.c:766), never the real filesystem ACL. The receiver then stores a stash only when rsync_acl_equal_enough() / rsync_acl_equal() find it differs from what the destination holds (set_acl_fdat(), acls.c:1388-1415).

oc diverged in two ways:

  • its sender fell back to the real ACL;
  • its receiver stored unconditionally.

Fix:

  • metadata::read_sender_acl is the one sender-side read. It is used by LocalAcls::read, the local fake-super sync, the engine batch writer and the network generator.
  • update_fake_super_access_acl / update_fake_super_default_acl add the equality gate to both store paths: the local copy, and the network receiver's file commit.

Behaviour change:

  • A local --fake-super -A copy of files that carry only permission bits now writes no ACL xattrs, as 3.5.1 does. A source's own stash is still carried.
  • An oc client --fake-super -A push no longer sends the real named ACL entries. 3.5.1's client sends only the stash too (oracle cell fake_super_push_sends_the_stash_not_the_real_acl).

--copy-unsafe-links without -l

readlink_stat() dereferences an unsafe link before -l matters (flist.c:482-506). oc skipped such links, both as an operand and inside a tree. The planner (both variants) and the operand handler now dereference them. A link that stays a link is still skipped when -l is off (generator.c:2109-2115).

Itemized row for a skipped non-regular entry

generator.c:2109-2115 prints skipping non-regular file "%s" and jumps to cleanup without itemizing. oc printed an extra .S/.L row for every such entry, not just links. emit_out_format now drops it.

Tests

  • tests/local_copy_skip_and_fake_super_parity.rs, 5 cells against 3.5.1:
    • a local stash, with a bait stash so the comparison can see one;
    • a fake-super push through an rsh shim;
    • an operand link;
    • in-tree links, with a safe-link bait;
    • skip rows.
  • metadata unit tests:
    • a mode-only ACL is not stashed; a named one is;
    • a stale stash is rewritten; an equal one is left untouched (ctime);
    • the default stash follows the source;
    • a fake-super sender reads only the stash.
  • sync_acls_via_fake_super_stashes_named_entry_instead_of_applying encoded the old fallback. It is replaced by sync_acls_via_fake_super_carries_the_stash_not_the_real_acl.
  • Mutations: 7 of 7 killed. They cover the access gate, the sender fallback, the skip-row filter, the planner dereference, the operand dereference, the safe-link demotion and the default gate.

Not in this PR

  • Task 599: the network receiver applies a directory's ACL for real under --fake-super instead of stashing it.
  • Task 600: under -i, 3.5.1 prints a directory's skip notices before its cd+++ row; the cells compare those rows as a set.

macOS local -X name mapping

Once the local copy read its xattrs as a list, it also sent names through oc's wire mapping and back:

  • protocol::xattr::local_to_wire keeps rsync.* names verbatim on non-Linux hosts. That is a documented deviation, owned by task 257.
  • wire_to_local mirrors 3.5.1's receive_xattr() (xattrs.c:887-901) and re-adds rsync. under am_root.
  • On macOS the pair turned rsync.nonuser.equal into rsync.rsync.nonuser.equal. This failed the xattrs and xattrs-hlink cells on both macOS pipe legs.

3.5.1's sender strips the prefix before it reaches the wire (xattrs.c:537-560), so its round trip is lossless.

Fix: the local list path now uses protocol::xattr::local_from_own_wire, the exact inverse of local_to_wire. No wire bytes change, and task 257 keeps the wire-side deviation.

Testing:

  • local_from_own_wire_inverts_local_to_wire checks the round trip for user., plain, rsync.nonuser, rsync.%stat, nested user.user. and non-UTF-8 names.
  • That test is a no-op on Linux. The fix itself is proven only by CI's macOS upstream-testsuite legs (xattrs, xattrs-hlink); I have no local macOS run.

@oferchen oferchen closed this Nov 4, 2026
@oferchen oferchen reopened this Nov 4, 2026
@oferchen
oferchen force-pushed the fix/local-acl-xattr-read-once branch from d8a5e4c to d42e743 Compare November 4, 2026 08:55
@oferchen
oferchen force-pushed the fix/local-acl-xattr-read-once branch from d42e743 to 6f0d44a Compare November 4, 2026 13:01
@oferchen
oferchen force-pushed the fix/local-acl-xattr-read-once branch from 6f0d44a to 99e3e2a Compare November 4, 2026 15:08
@oferchen oferchen closed this Nov 10, 2026
@oferchen oferchen reopened this Nov 10, 2026
@oferchen oferchen closed this Nov 10, 2026
@oferchen oferchen reopened this Nov 10, 2026
@oferchen
oferchen force-pushed the fix/local-acl-xattr-read-once branch from 99e3e2a to d3784fa Compare November 10, 2026 12:13
@oferchen
oferchen force-pushed the fix/local-acl-xattr-read-once branch from d3784fa to 24ae70d Compare November 10, 2026 12:45
@oferchen
oferchen force-pushed the fix/local-acl-xattr-read-once branch from 24ae70d to bda8fd1 Compare November 10, 2026 14:13
@oferchen oferchen closed this Nov 10, 2026
@oferchen oferchen reopened this Nov 10, 2026
@oferchen
oferchen force-pushed the fix/local-acl-xattr-read-once branch from bda8fd1 to 7d4946f Compare November 10, 2026 17:46
@oferchen
oferchen force-pushed the fix/local-acl-xattr-read-once branch from 7d4946f to 3fbc26e Compare November 10, 2026 19:10
@oferchen
oferchen force-pushed the fix/local-acl-xattr-read-once branch from 3fbc26e to c478ee8 Compare November 10, 2026 20:35
@oferchen oferchen closed this Nov 10, 2026
@oferchen oferchen reopened this Nov 10, 2026
@oferchen
oferchen merged commit 4aa461c into master Nov 11, 2026
100 of 103 checks passed
@oferchen
oferchen deleted the fix/local-acl-xattr-read-once branch November 11, 2026 05:00
oferchen added a commit that referenced this pull request Nov 11, 2026
fix: apply a local -M to the receiver half only

Fixes the required upstream-testsuite regression `fake-super-acl-xattr`
that #8332 brought to master. Tasks 520, 540 and 641.

## Problem

On master, a local copy folds its `-M` values into the client argv, so
both halves read one option set. Under `-rA -M--fake-super` that makes
the sender fake-super too. It then reads only the source's (empty)
`%aacl` stash, and dst gets no `%aacl`/`%dacl`. The upstream test fails
with "--fake-super -A should have stored user.rsync.%aacl on dst/f".

3.5.1 forks the receiver, and only the receiver re-parses the `-M`
values (pipe.c:143-148). The sender reads the real ACL (acls.c:609-631),
and the receiver stashes it with set_xattr_acl (acls.c:933-971).

#8332's 540 measurement still holds where both halves run fake-super:
`-rA --fake-super` with no `-M`. 3.5.1 stores no `%aacl`/`%dacl` there,
re-measured with a named-user ACL and a default dir ACL. That behaviour
is unchanged.

## Commits

1. `refactor: split the client run into a repeatable translation pass`.
Behaviour-neutral: `execute()` runs `translate()` with a `Pass`, and the
process setup runs only on the process pass. The order of every early
return and side effect is kept. A test checks that a `--help` early
return reads no files and opens no log file.
2. `fix: apply a local -M to the receiver half only`. Two option sets,
described below.

### Mechanism

3.5.1 forks the receiver for a local copy. In `pipe.c:109-148`
`local_child()`, the child inherits the client's options and re-runs
`parse_arguments()` over the `-M` values on top of them. The parent
sender keeps the client's own options. So every `-M` option changes the
receiver half only.

oc used to fold `-M` into the client argv, which gave one option set for
both halves. That set was wrong for the sender whenever `-M` named
something the sender reads. Now it keeps two option sets, as upstream
does:

- cli: `parse_args` keeps the client's own parse as
`ParsedArgs.local_sender`, but only when a fold happened. The folded
parse is the receiver's. Each set's filter order is built from the argv
it was parsed from.
- `execute()` runs the real process setup on the client's own parse, as
3.5.1's `main()` does, and that parse is also the sender's set. The `-M`
fold, the receiver's set, is translated on an inert pass (commit 1:
`translate()`/`Pass`). The inert pass sets no globals, opens no log file
and reads no password; pipe.c:131-141 clears the child's log file. It
replays the `--files-from` list the process pass read rather than
reading it again; pipe.c:133 sets the child's `filesfrom_fd = -1`. The
run takes its output settings from the client parse and its config from
the receiver set, with the sender's attached by
`ClientConfig::with_local_sender()`.
- core builds the sender's `LocalCopyOptions` from it, with its own
filter program, and attaches it with
`LocalCopyOptions::with_local_sender()`.
- engine: `LocalCopyOptions::sender_half()`
(`CopyContext::sender_options()`) returns the sender's set when there is
one, and `self` otherwise. Without `-M` both halves read one set, and
behaviour is unchanged.

### Side table: which half reads what

| read | half | upstream | oc |
|---|---|---|---|
| `-r` / `-d` (walk, `xfer_dirs`) | sender | flist.c:2436, :2751, :2992
(no generator.c read) | `recursive_enabled`/`dirs_enabled` facades |
| `-L` / `-k` / `--copy-unsafe-links` | sender | flist.c:417, :485,
:492, :514; sender.c | `copy_*_enabled` facades,
`follow_source_symlinks` |
| `--files-from` | sender | flist.c:2787-2809; pipe.c:133 clears it in
the child | `files_from_enabled` |
| filter hide (transfer) | sender | flist.c:1662, :1731 `is_excluded` |
`CopyContext.filter_program` + `dir_merge` |
| filter protect / delete | receiver | generator.c:285 `delete_in_dir`,
:1750 | `receiver_filter_program` + `delete_dir_merge` |
| xattr names the receiver may set | receiver | xattrs.c `rsync_xal_set`
| `CopyContext::filter_program()` (xattr sync) |
| source stat under `--fake-super` | sender | flist.c:497-516
`x_stat`/`x_lstat`; xattrs.c:1372 | virtualize sites (11),
`ensure_fake_super_source_stat`, `fake_super_source_stat`,
`store_effective_fake_super_if_requested`, hard-link holder reorder |
| source ACL/xattr read under `--fake-super` | sender |
flist.c:2052-2062 `get_acl`/`get_xattr`; acls.c:599-607 |
`source_attrs.rs`, batch ACL read, `FakeSuperSides.sender` |
| `%stat` / `%aacl` store | receiver | xattrs.c:1304-1356
`set_stat_xattr`; acls.c:933-971 | unchanged (`fake_super_enabled`) |
| `-R` (names) | sender | flist.c:1077, :1753 |
sources/orchestration.rs, sources/metadata.rs |
| `-R` (dest parents) | receiver | generator.c, receiver.c |
context_impl/options/dirs.rs, unchanged |
| `--no-implied-dirs` | receiver | generator.c (dir attrs) | unchanged |
| `-x` (walk) | sender | flist.c:1375, :1715, :2574, :2989 | planner.rs,
sources/orchestration.rs, recursive/mod.rs |
| `-x` (delete boundary) | receiver | generator.c:316, :1915 |
cleanup.rs, obstacle.rs, unchanged |
| everything else | receiver | the forked child | unchanged |

### Cells (MEASURED, same commands against the 3.5.1 tarball build)

| command | 3.5.1 | oc before | oc now |
|---|---|---|---|
| `-d -M-r` | `d/` only | recursed | `d/` only |
| `-r -M--no-r` | full tree | "skipping directory ." | full tree |
| `-r -M-R` | non-relative names | `tmp/...` relative tree |
non-relative names |
| `-r --delete -M--exclude=*.tmp` | `x.tmp` sent, dest `y.tmp` kept, `z`
deleted | `x.tmp` hidden | as 3.5.1 |
| `-r -M--fake-super`, source 0644 with `%stat 100600` | 0644, `%stat
100644 0,0 0:0` | 0600, `100600` | as 3.5.1 |
| `-rA -M--fake-super`, named-user ACL | `%aacl` stashed | none |
stashed |

Cells that stay identical, checked so the split cannot move them:
`-M--chmod=o+r` (the receiver applies it; 604 on both), `-M-p`, `-M-x`,
`-M--copy-dirlinks`, `-M--remove-source-files`.

Tests:
- `tests/local_remote_option_sides.rs`: 5 oc-only cells that assert the
measured 3.5.1 results, so they run in CI without the oracle.
- `tests/local_copy_skip_and_fake_super_parity.rs`:
- `receiver_only_fake_super_ignores_the_source_stat_record`: the %stat
cell (task 641), oc-only.
- `receiver_only_fake_super_stashes_the_real_source_acl`: the ACL cell,
oracle comparison.
- `options/sides.rs` unit tests.
- `cli` `help_returns_before_the_process_pass_reads_its_files`: a help
early return still reads no files and opens no log file.

### Not covered

- 3.5.1 itself breaks on `-M-l` (rc 22, `recv_file_entry` overflow),
`-M--no-l` (hang) and `-M-c` (rc 2, "File-list index ... not in"). These
options change the flist shape, so the two halves stop agreeing on the
wire format. There is nothing to mirror, so there are no cells.
- `-rl -M--copy-links`: 3.5.1 keeps the link. oc refuses the folded
receiver argv with a clap conflict between `-l` and `-L`, which 3.5.1
accepts. Filed as task 642 and not folded in, per review.
- A `-M` rule that adds a per-dir merge file loads on the receiver chain
only. That is correct, but no cell covers it.
- On the process pass, the cli still sets its globals (SIMD override,
logging) before the help check, the same order as before this PR.
- A `-M` option that 3.5.1 applies per process but oc applies once per
run takes the client's value in oc. Output levels are the main case. In
3.5.1, `-M-v` makes the forked receiver print `created directory t`
(main.c get_local_name), and `-M-vv` adds the generator's
`delta-transmission disabled for local transfer or --whole-file`. The
client's own output is unchanged. oc prints neither, because its
verbosity, itemize, info/debug and out-format are process-global and
come from the client parse. These are listed, not approximated.
- `-M--log-file=F`: pipe.c:136-140 clears the inherited log file in the
receiver, and the `-M` value parsed after it opens the receiver's own.
oc opens F from the receiver set when the client parse names no log
file. That keeps `remote_option_applies_to_a_local_transfer`. When both
name a log file, oc writes only the client's, while 3.5.1 writes
receiver lines to F as well.
- `-M--copy-links` stays a symlink in 3.5.1. oc's receiver-side parse
still refuses `-l` together with `-L` (task 642), so that cell waits for
it.

### Upstream testsuite (fake-super-acl-xattr, host, 3.5.1 tarball suite)

- non-root: `PASS    fake-super-acl-xattr`
- root: `PASS    fake-super-acl-xattr`

The three legs of fake-super-acl-xattr_test.py:89-111 were also replayed
directly, against both 3.5.1 and oc. All three give identical results:
- `-rA -M--fake-super`: `%aacl` on f, `%dacl` on d.
- `-rA --fake-super -M--fake-super`: both kept.
- re-sync after `setfacl -k`: `%dacl` removed.

The other host-only failures in the same runs are not caused by this PR:
- non-root `rrsync-userns-procfs`: "cannot locate the rsync executable"
for the debug binary path.
- root `operator-path-dir-daemon-leaf` and
`operator-path-partial-dir-exclude-daemon`: both compare against a
host-only 3.2.7 oracle, and both are daemon `--partial-dir` cells.
oferchen added a commit that referenced this pull request Nov 13, 2026
## Summary

Under `--fake-super`, the network receiver now stashes every received
ACL in the `%aacl`/`%dacl` xattrs instead of applying it, as 3.5.1 does.
Before, only regular files written through disk_commit took the stash
path. Directories, devices, specials, alt-dest matches, batch replay and
up-to-date files got the real ACL applied, and they had no stash.

Stacked on #8332.

## Changes

1. `fix: keep group_obj when condensing a wire-received fake-super ACL`
- `RsyncAcl::condense_for_fake_super_store` re-applied the sender's
strip (`rsync_acl_strip_perms()`, acls.c:142-159) to an ACL that had
already been stripped on the wire.
- When the mask was stripped (it equals the mode's group bits), the
second strip saw `mask == NO_ENTRY` and also blanked a `group_obj` that
differs from the mask.
- 3.5.1 stores that `group::` entry (acls.c:1228-1238, `duo_item->racl`
verbatim after recv_rsync_acl()'s mask restoration, acls.c:1000-1007).
- The mask restoration now runs before the strip as well, so a
filesystem-read ACL and a wire-received ACL condense to the same stored
form.
- This also fixes the existing transferred-file path, which had the same
loss.
2. `fix: stash ACLs under --fake-super on every receiver path`
- `apply_acls_from_receiver_cache` (transfer
`receiver/pipeline_setup.rs`) takes `fake_super`. When it is set, it
calls `store_acls_via_fake_super` (upstream: acls.c:1228
`set_rsync_acl()`, `am_root < 0` arm).
- All six callers pass it: directory creation (x2), specials, alt-dest
quick-check, the candidate quick-check match and batch replay.

## Evidence

- New oracle test `tests/fake_super_receiver_acl_stash.rs`:
- A 3.5.1 client pushes `-rtA -M--fake-super` to each server (3.5.1,
oc).
- The fixture is a directory with access and default named ACLs and a
file with a named ACL.
- The client then pushes again after changing the source ACLs (mask
above `group::`), which reaches the existing directory and the
up-to-date file.
- Real ACLs and stashes must match between the servers, and the oracle
must show stashes and no real named entries.
  - It passes against the 3.5.1 tarball binary.
- New unit test
`condensing_the_wire_form_keeps_a_group_obj_below_the_mask`.
- Mutations, each caught:
  - Drop the leading mask restore: unit test and oracle cell fail.
- Ignore `fake_super` in `apply_acls_from_receiver_cache`: oracle cell
fails.
- Pass `false` at the up-to-date-file call site: oracle cell fails
(second round).
- Gates:
  - fmt-all: ok.
  - Workspace clippy: ok.
  - windows-gnu clippy (transfer, metadata, protocol): ok.
- No-default clippy for transfer, protocol and metadata, plus transfer
with `xattr` only and with `acl` only: ok.
  - dead_code_census: OK.
  - Citation ratchet: OK.
- Targeted nextest (protocol, metadata, transfer, bin; acl / fake_super
filters): 521/521 passed.

## Not in scope

- `%stat` ids under `--fake-super` without `-o`/`-g`: 3.5.1 wrote
`2465469312:2465469312` for a file where oc writes `0:0`. Tracked in
task 496.
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