Skip to content

fix: report make_path's own errno when --mkpath meets a file - #8901

Merged
oferchen merged 3 commits into
masterfrom
fix/local-mkpath-errno
Nov 28, 2026
Merged

oferchen merged 3 commits into
masterfrom
fix/local-mkpath-errno

Conversation

@oferchen

@oferchen oferchen commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

Summary

A local copy with --mkpath into a destination whose path runs through a
regular file printed an invented line, failed to inspect destination, and
exited 23. rsync 3.5.2 prints mkdir "<dest>" failed: <make_path's errno> and
exits 11.

rsync 3.5.2:

  • get_local_name() hands a destination that does not stat to make_path()
    (main.c:757-761). A failure jumps to mkdir_error (main.c:818-821):
    mkdir %s failed with full_fname(dest_path) as given (trailing slash
    kept), then RERR_FILEIO (11).
  • make_path() (util1.c:231-247) tries the deepest directory first and climbs
    only on ENOENT, so the errno reported is the deepest mkdir's. EEXIST
    counts as success only for a directory (util1.c:244-246).
  • For a relative destination the receiver's do_mkdir_at() opens the parent
    through secure_relative_dirfd(), which reports a non-directory
    intermediate as ELOOP (syscall.c:3279-3281). An absolute destination uses
    plain mkdir() and keeps ENOTDIR.

This change:

  • engine: a destination stat error under --mkpath no longer aborts; the
    destination goes to make_path, and its failure renders as
    mkdir "<dest>" failed with exit 11. The --mkpath line keeps the trailing
    slash (main.c:760); the plain-mkdir line still cuts it (main.c:815).
  • engine: the single-entry parent is made only when it is not already a
    directory (util1.c:244-246).
  • fast_io: make_path_beneath_cwd walks deepest-first like make_path, and maps
    a non-directory intermediate to ELOOP the way secure_relative_dirfd
    does. The absolute arm uses operator_make_path.
  • transfer: the network receiver's counting pass stops at ENOTDIR so the
    making pass reports the errno (the same deepest-first rule as fix: walk a network receiver destination before mkdir #8899).
  • core: the destination-mkdir renderer prints the path as given.

Measured, rsync 3.5.2 vs this branch

dst/dstfile is a regular file. Errno printed; every cell exits 11 on both.
Local, push and pull give the same results.

Shape Relative Absolute
f dst/dstfile/x 17 17
f dst/dstfile/x/ 20 20
f dst/dstfile/x/y/ 40 20
f dst/dstfile/x/y 20 20
-r dst/dstfile/x 20 20
-r dst/dstfile/x/y/ 40 20

Before this change, a local copy printed failed to inspect destination and
exited 23 for every row. A network receiver given a relative destination
printed 20 where 3.5.2 prints 40.

No deviation from rsync 3.5.2.

Tests

  • New crates/cli/tests/mkpath_through_a_regular_file.rs: the 6 shapes x
    relative/absolute on the local, push and pull legs. Each cell runs oc to oc,
    and when OC_RSYNC_UPSTREAM_BIN_3_5_2 resolves also 3.5.2 to 3.5.2 and both
    mixed pairs. Asserts exit 11, the exact mkdir "<path>" failed: <strerror> (<n>) line, no invented text, and that the regular file survives. The
    strerror and errno come from the kernel, not from strings in the test.
  • crates/fast_io/tests/make_path_beneath_cwd.rs: a regular file as the
    deepest directory's parent gives ENOTDIR; one higher gives ELOOP.

Mutations, each restored afterwards:

Mutation Result
make_path walks forward from the root cli 3 tests red, fast_io 4 red
no ELOOP mapping for a non-directory intermediate cli 3 red, fast_io 2 red
destination stat error aborts again local red
receiver counting pass ignores ENOTDIR push and pull red
parent guard made unconditional local red

Verification

  • cargo fmt --all -- --check: clean
  • cargo clippy --workspace --all-targets --all-features --no-deps -- -D warnings: clean
  • the same clippy for x86_64-pc-windows-gnu: clean
  • cargo doc --workspace --all-features --no-deps --locked: clean
  • cargo nextest run -p cli --test mkpath_through_a_regular_file with the
    3.5.2 oracle required (OC_RSYNC_UPSTREAM_COMPAT=1): 3 passed
  • cargo nextest run -p fast_io --test make_path_beneath_cwd: 8 passed
  • lib tests for fast_io, engine, transfer and core: 11873 passed
  • -p engine -p fast_io -p transfer -E 'test(mkpath) | test(make_path) | test(destination) | test(dest_root)': 338 run, 323 passed. The 15 failures were tests that
    spawn oc-rsync before it was built; after cargo build -p bin, a rerun of
    those 15 (39 matching tests) passed.
  • On master-identical rsync_io, the 3 ssh_config_differential cells fail
    on the build host: its ssh is OpenSSH_10.6p2, which rejects the
    transport keyword. This branch does not touch rsync_io.
  • Not run on the host: bin's destination_root_owner_walk needs root or
    passwordless sudo. It runs in the nextest and musl jobs.

A local --mkpath into a destination whose chain holds a regular file
printed an invented inspect-destination line and exited 23. rsync
3.5.2 hands an unstattable destination to make_path() and prints
mkdir %s failed with the deepest mkdir's errno, exiting 11.

make_path_beneath_cwd now tries the deepest directory first and maps a
non-directory intermediate to ELOOP like secure_relative_dirfd(), the
absolute arm uses operator_make_path, and the network receiver lets
that walk report the errno instead of its counting stat.
@oferchen oferchen added this to the 0.6.5 milestone Nov 28, 2026
@github-actions github-actions Bot added the bug Something isn't working label Nov 28, 2026
@oferchen
oferchen merged commit 54830a9 into master Nov 28, 2026
90 checks passed
@oferchen
oferchen deleted the fix/local-mkpath-errno branch November 28, 2026 07:42
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