Skip to content

fix: report a failed destination-root mkdir as RERR_FILEIO on every path - #8344

Merged
oferchen merged 5 commits into
masterfrom
fix/local-dest-mkdir-fileio
Nov 13, 2026
Merged

oferchen merged 5 commits into
masterfrom
fix/local-dest-mkdir-fileio

Conversation

@oferchen

@oferchen oferchen commented Nov 10, 2026 •

Copy link
Copy Markdown
Owner

Summary

When rsync cannot create the destination root, 3.5.1 exits 11 (RERR_FILEIO) with mkdir "<dir>" failed: <errno> on every transfer path. oc exited 23 on a local copy and 3 on an rsh or daemon push. This PR fixes all three paths, which share one cause (tasks 585, 576 and 611).

Upstream: main.c:808-821 get_local_name(). When file_total > 1 || trailing_slash, it calls do_mkdir(); with --mkpath, make_path() jumps to the same label. On failure it prints rsyserr(FERROR, errno, "mkdir %s failed", full_fname(dest_path)) and exits RERR_FILEIO. This runs before do_recv() forks, so the line and the trailer name the unforked Receiver (rsync.c:987-995).

Changes

  • Local copy (585):
    • The engine reports the failure as a new DestinationMkdirFailed kind (exit 11).
    • The client renders it as rsyserr's program line with the [Receiver= trailer.
  • When a local copy creates the destination root up front (main.c:808): one function, file_total_exceeds_one (new sources/file_total.rs), now decides it the way upstream's first file list counts:
    • Every operand counts, a repeated one twice (flist.c:3060). The plan keeps a per-operand repeat count, since it dedups operands.
    • Missing operands, filtered-out operands and directories skipped without -r/-d count nothing (flist.c:2937-2966).
    • A lone expanded directory adds its contents (flist.c:3096 send_extra_file_list()), judged by the same rules the walk applies there, its per-dir merge files included. A directory whose every child is excluded stays a single entry, so the destination becomes that directory and a mkdir failure is recv_generator's per-file error (exit 23).
    • This replaces two ad hoc predicates that read the raw directory.
    • Visible fixes beyond the mkdir failure: -d src/ dst and a a dst now create dst/ like 3.5.1, and -rL/-rk of a symlink to a directory now lands at dst/<link>/... like 3.5.1 (oc copied the contents into dst/ itself; the three engine tests that pinned that are corrected).
  • rsh (576) and daemon (611) receivers:
  • Daemon path rendering: the daemon renders the root module-relative, as "ro/new" (in m). The daemon skips change_dir#4 (main.c:1212), so full_fname uses the module form (util1.c:1528).

Evidence

The 3.5.1 oracle is the tarball build (~/up351/rsync-3.5.1/rsync). The fixture is a destination ro/new, where ro is 0555.

Path Client vs server 3.5.1 exit oc exit First line
local -r src ro/new/ - 11 11 rsync: [Receiver] mkdir "…/ro/new" failed: Permission denied (13)
local -r src/ ro/new - 11 11 same
local -r a b ro/new - 11 11 same
rsh push oc vs oc 11 11 same, server-side
rsh push 3.5.1 vs oc 11 11 same
rsh push oc vs 3.5.1 11 11 same
daemon push oc vs oc 11 11 mkdir "ro/new" (in m) failed
daemon push 3.5.1 vs oc 11 11 same, plus a residual (below)
daemon push oc vs 3.5.1 11 11 same

Local operand edges of the main.c:808 rule, destination ro/new under a 0555 ro, 3.5.1 exit vs oc exit (all match except the two pre-existing rows marked):

Operands 3.5.1 oc
-r src, -r src/, -r src/ ro/new/, -R src, -R src/ 11 11
-r src/ with every child excluded; -r src likewise 23 23
-r empty/ 23 23
-d src/ 11 11
-d src 23 23
a a (same file twice) 11 11
a b 11 11
one file; one file into ro/new/ 23; 11 23; 11
--mkpath src/ ro/x/new 11 11
-rn src/ 0 0
a missing (pre-existing, task 623) 23 11
-R src/a (pre-existing, task 623) 11 23

The success-path trees match 3.5.1 for two files, -d src/, every child excluded (with and without the slash), a file given twice and one child excluded.

The happy path is unchanged against 3.5.1 for -ri, -rv, --stats, -rin and -di.

Tests: tests/server_error_exit_code_reaches_client.rs gains cells per path: local_copy_dest_mkdir_failure_reports_file_io, the existing rsh cell, daemon_dest_mkdir_failure_reports_file_io, and local_copy_dest_root_mkdir_follows_file_total (every child excluded: 23; -d src/: 11; a file given twice: 11). Each runs under both the oc client and the 3.5.1 client. Engine tests:

  • permission_destination_mkdir_denied_exits_file_io (new).
  • execute_directory_source_deep_missing_dest_errors_without_mkpath (now expects exit 11).
  • core map_destination_mkdir_failed_reports_file_io_as_receiver.

Mutation, each mutant run against the targeted filter:

  • M1 (engine maps back to the generic io error) is killed by 3 tests: both engine tests and the local cell.
  • M4 (children judged by the raw directory, not the filter rules) is killed by local_copy_dest_root_mkdir_follows_file_total (every child excluded).
  • M5 (-d copy-contents not expanded) is killed by the same test (-d src/).
  • M6 (a repeated operand counted once) is killed by the same test (file given twice).
  • M3 (server mkdir arm disabled) is killed by 3 tests: the rsh cells and the daemon cell.

Gates on the amended head, rebased on 75c4a1d (after #8321):

  • tools/ci/check_rustfmt_all.py OK.
  • clippy -D warnings --all-targets --all-features clean on engine, core, cli, transfer, embedding and daemon.
  • cargo nextest -p engine 4952/4952, plus the cli server, signal, error-exit and local-copy cells.

Residual

  • Task 623, pre-existing: a missing dst exits 11 (3.5.1: 23, file_total 1); -R src/a dst refuses with oc's own text (3.5.1: 11, the implied src counts).
  • Pre-existing, outside this PR: under -m, a top-level operand excluded by - * is still walked by oc; 3.5.1 lists nothing. The new count mirrors oc's walk there, so behaviour is unchanged.

A 3.5.1 client against an oc daemon prints one extra trailing line, [sender] read error: Connection reset by peer (104), after the matching mkdir line and exit 11. This is task 232 (echo MSG_ERROR_EXIT and drain until the peer exits), not part of this PR.

@oferchen
oferchen force-pushed the fix/local-dest-mkdir-fileio branch from bd84f3f to f58c293 Compare November 10, 2026 15:13
@oferchen oferchen closed this Nov 10, 2026
@oferchen oferchen reopened this Nov 10, 2026
@oferchen
oferchen force-pushed the fix/local-dest-mkdir-fileio branch from f58c293 to de41e63 Compare November 10, 2026 17:52
@github-actions github-actions Bot added the bug Something isn't working label Nov 10, 2026
@oferchen
oferchen force-pushed the fix/local-dest-mkdir-fileio branch 2 times, most recently from 7aed4df to b1fa129 Compare November 10, 2026 20:35
@oferchen
oferchen force-pushed the fix/local-dest-mkdir-fileio branch 3 times, most recently from 80f9e2f to 0a6a71b Compare November 11, 2026 10:32
@oferchen
oferchen force-pushed the fix/local-dest-mkdir-fileio branch 2 times, most recently from cb27979 to 435f882 Compare November 11, 2026 10:55
@oferchen

Copy link
Copy Markdown
Owner Author

Merge train: this pull request failed its batch run on its own (https://github.com/oferchen/rsync/actions/runs/43031147828). Failed required checks: upstream-testsuite / upstream testsuite, . It is held out of batches until its head changes.

oferchen added a commit that referenced this pull request Nov 11, 2026
…8360)

## Summary

A daemon session's process now exits with the code its transfer ended
on, and the daemon log carries log_exit()'s lines in place of an
invented summary, as rsync 3.5.1's per-connection child does.

- **Exit status** (cleanup.c:213-218, :264):
- A transfer that runs to its end maps `io_error` and `got_xfer_error`
to its code via `core::exit_code::io_error_exit_code`, so a partial
transfer exits 23.
- A fatal transfer exits with the peer's `MSG_ERROR_EXIT` code if one
arrived (io.c:1930), otherwise with its own RERR code.
- The code goes into `session_exit_code`. The forked TCP child now exits
with it; before, it dropped it via `.map(|_| ())` and always exited 0.
The stdio and inetd sessions already turned that field into their exit
status.
- **Daemon log** (log.c:937-963, log.c:310-327):
- A fatal error logs the cause line and the `rsync error: ... (code N)`
trailer from `fatal_report_lines`, the same lines the client is sent.
This replaces the invented `transfer failed to HOST (IP): module=M
error=E` line.
- The `sent ... received ... total size` line is written only for a
clean exit or a sender (log.c:941).
- A partial transfer's end-of-run exit logs no trailer (`am_server = 2`,
cleanup.c:121-122).
- **Abortive close** on the receiver now keys on a fatal error rather
than on a nonzero code, so a partial push (code 23) keeps the graceful
close.

## Evidence

All cells are measured against the 3.5.1 tarball build. Server exit
statuses come from strace (TCP daemon) or an rsh shim (daemon mode via
`--rsync-path`).

| cell | 3.5.1 server | oc before | oc after |
|---|---|---|---|
| pull of a missing file | exit 23, totals | exit 0, totals | exit 23,
totals |
| clean pull | exit 0, totals | exit 0 | exit 0, totals |
| push with an unreadable source subdir (receiver io_error) | exit 23,
no totals, no trailer | exit 0, totals | exit 23, no totals, no trailer
|
| push into a 0555 dir | exit 11, mkdir cause + trailer | exit 0,
`transfer failed to` line | exits with the trailer's code, trailer
logged (3, see residuals) |

`tests/daemon_session_exit_status.rs` covers four cells in rsh daemon
mode and asserts the server process's exit status and the daemon log. It
is deterministic: the oc client reaps its rsh child before exiting. The
unreadable-dir cell skips with a printed reason when run as root.

**Mutants, all killed:**
- A partial transfer exits 0: two cells.
- A receiver logs totals on code 23: the io_error push cell.
- Nothing is logged on a fatal error: the fatal push cell.
- `session_exit_code` is not set: three cells.
- A fatal error exits 1: the fatal push cell.

## Residuals

- **Push into a 0555 dir:** oc reports code 3 where 3.5.1 reports 11
with the `mkdir ... failed` cause. That is #8344 (local) and task 611
(daemon); this PR makes the session exit with whatever code is reported.
- **Trailer role tag:** it says `[generator=` on the receiver; 3.5.1
says `[Receiver=` for the pre-fork mkdir.
- **Sender totals on a fatal exit:** oc's sender logs none, because it
has no stats on the error path. 3.5.1 logs them even on error
(log.c:941).
- **Missing source:** the oc daemon sender logs neither the `link_stat
... failed` line nor the real totals. That is task 280.
- **Forked TCP child's exit status:** a test can't observe it. The
parent records it only at `--debug=EXIT`, and upstream discards it. The
strace oracle cell above covers it, and the rsh cells exercise the same
`session_exit_code` path.

## Test plan

- [x] `python3 tools/ci/check_rustfmt_all.py`
- [x] Workspace clippy with all features, plus no-default-features
clippy of `daemon`
- [x] `cargo nextest run -p daemon --all-features`: 2152 passed
- [x] Targeted `-p bin` (178), `-p core` and `-p transfer` (530) daemon,
inetd and stdio tests
- [x] 3.5.1 oracle: TCP strace exits and rsh daemon-mode statuses and
logs
upstream main.c:817-821 get_local_name() makes the destination root with
one do_mkdir() (make_path() under --mkpath jumps to the same label) and on
failure prints `mkdir %s failed` through rsyserr(), then exits RERR_FILEIO.
It runs before do_recv() forks, so the line and the log_exit() trailer name
the unforked `Receiver` (rsync.c:987-995). oc exited 23 on a local copy and
3 on an rsh or daemon push.

- local copy: the engine reports the failure as DestinationMkdirFailed
  (exit 11), which the client renders as rsyserr's program line plus the
  `[Receiver=` trailer
- a local copy decides the pre-flight mkdir from upstream's file_total > 1
  (main.c:808): the operands of the first file list, a repeated one
  counted twice, after the filter rules, plus the contents of a lone
  expanded directory (flist.c:3096); `src/`, `-d src/` and a file given
  twice now take it, a directory whose every child is excluded does not,
  and a followed directory symlink keeps its name under the destination
- rsh and daemon receivers wrap the cause in DestRootMkdirError, which
  grades RERR_FILEIO; the server writes its report through the fatal
  report hook before MSG_ERROR_EXIT, on the fds and stdio entries alike
- a daemon renders the root module-relative, `"dir" (in module)`
  (util1.c:1528)
@oferchen
oferchen force-pushed the fix/local-dest-mkdir-fileio branch from 435f882 to 090e921 Compare November 12, 2026 23:19
@oferchen
oferchen merged commit ecc2e6f into master Nov 13, 2026
155 of 156 checks passed
@oferchen
oferchen deleted the fix/local-dest-mkdir-fileio branch November 13, 2026 02:36
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