Skip to content

refactor: share one change_dir#N formatter across receivers - #8902

Merged
oferchen merged 1 commit into
masterfrom
refactor/shared-change-dir-formatter
Nov 28, 2026
Merged

oferchen merged 1 commit into
masterfrom
refactor/shared-change-dir-formatter

Conversation

@oferchen

Copy link
Copy Markdown
Owner

Summary

rsync 3.5.2 prints one line when the receiver cannot enter its destination:
rsyserr(FERROR, errno, "change_dir#N %s failed", full_fname(..)) in
get_local_name():

  • change_dir#1 (main.c:779): an existing destination directory
  • change_dir#2 (main.c:837): a destination directory the run created
  • change_dir#3 (main.c:866, main.c:982): the parent of a single-file destination

rsyserr() appends : <strerror> (<errno>) (log.c:575-585).

oc wrote this text in three places:

  • transfer receiver/dest_root.rs: the SelectStep Display (push and pull receivers)
  • core client/error.rs: the local-copy error mapping
  • engine local_copy/error.rs: the DestinationEntryFailed message

All three now render through one formatter, logging::ChangeDirFailed.
logging is the only crate all three already depend on (transfer does
not depend on engine).

Design

  • logging::ChangeDirStep { One, Two, Three }. change_dir#4
    (main.c:1214) has no caller in oc, so it gets no variant.
  • logging::ChangeDirFailed::new(step, fname, cause) renders
    change_dir#N <fname> failed: <upstream_errno_text>. The rsync: [role]
    prefix stays with the caller, as before.
  • fname arrives already rendered by full_fname(). Each caller keeps its
    own name rules: change_dir#1 keeps the operand's trailing slash
    (main.c:779 prints dest_path as given); change_dir#2 lops it
    (main.c:810).
  • Callers keep their own step enums and map them onto ChangeDirStep.
    engine::DestinationEntry::number() becomes change_dir_step().

Output

User-visible text is unchanged. The core and transfer lines were already
byte-for-byte upstream's, and the call sites now produce the same bytes
through the shared formatter. Engine's DestinationEntryFailed Display is
not printed to users (core's map_local_copy_error builds the user-visible
line); it now uses full_fname() like the other two, not "{path}".

Oracle cells for #8890 (local copy) and #8899 (network receivers), run on
master and on this branch, with OC_RSYNC_UPSTREAM_BIN_3_5_2 set to rsync
3.5.2 and OC_RSYNC_UPSTREAM_COMPAT=1 so 3.5.2 is required:

Target master this branch
core --test untrusted_destination_symlink 14/14 14/14
cli --test receiver_preflight_refusals --test mkpath_through_a_regular_file 12/12 12/12
bin --test destination_root_owner_walk (root via sudo) 9/9 9/9
transfer --lib test(dest_root) 4/4 4/4
core --lib test(change_dir) | test(destination_entry) 2/2 2/2
engine --lib test(change_dir) | test(destination_entry) 3/3 3/3

The same 44 cells by name, all passing, before and after.

Tests

New logging unit table (change_dir.rs):

  • Each step is checked against upstream's literal format string (main.c:779,
    :837, :866), with %s filled in and the rsyserr() tail appended.
  • The errno comes from a real failed read_dir, so the tail is the
    platform's own strerror text, not a string the test writes.
  • A second test checks the name is printed as given.

Mutations, each restored afterwards:

Mutation logging unit core local-copy cells bin network cell
(a) change_dir #N (space added) 2/2 red 6/14 red 1/9 red
(b) steps Two and Three swapped 2/2 red 5/14 red 1/9 red
(c) failed dropped 2/2 red 6/14 red 1/9 red

A mutation in the shared formatter turns the core and bin cells red, so both
the local-copy path and the network receivers go through it.

Verification

  • cargo fmt --all -- --check, tools/ci/check_rustfmt_all.py: clean
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings: clean
  • the same clippy for x86_64-pc-windows-gnu: clean
  • RUSTDOCFLAGS="-D warnings" cargo doc --workspace --all-features --no-deps --locked: clean
  • cargo run --locked -p xtask -- no-placeholders: OK
  • python3 tools/ci/citation_drift_audit.py --ratchet: OK

The change_dir#N line that get_local_name() prints (main.c:779, :837,
:866, :982) was written in three places: the transfer receiver's
SelectStep Display, the core local-copy error mapping and the engine
DestinationEntryFailed message. All three now render through
logging::ChangeDirFailed, so the text has one source.

ChangeDirStep has the three steps a caller can reach. change_dir#4
(main.c:1214) has no caller and gets no variant. Callers keep their
own name rules (trailing slash, full_fname) and map their step enums
onto ChangeDirStep; DestinationEntry::number() becomes
change_dir_step(). User-visible output is unchanged.
@oferchen oferchen added this to the 0.6.5 milestone Nov 28, 2026
@oferchen
oferchen merged commit c87bc25 into master Nov 28, 2026
90 checks passed
@oferchen
oferchen deleted the refactor/shared-change-dir-formatter branch November 28, 2026 09:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant