Skip to content

fix(executor): classify emulated cp operand stat errors by the path walk - #3426

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/issue-3416
Nov 12, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/issue-3416

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Fixes #3416

What

The emulated cp's operand gates collapsed every stat failure into a hardcoded ENOENT text: the source gate tested the boolean CpNode::exists() and the multi-source target gate did the same. A path spelled through a regular file (cp -r a/b dest with a a plain file) dies its walk at the non-directory component, and GNU coreutils reports that walk's ENOTDIR — the name and exit status were already right, only the errno class in the message was wrong:

  • GNU: cp: cannot stat 'a/b': Not a directory
  • base: cp: cannot stat 'a/b': No such file or directory

Mechanism

CpNode gains stat_classified(): it keeps stat()'s own error and re-derives the walk verdict for a bare NotFound — the shape where the class is genuinely lost (the Windows face answers ERROR_PATH_NOT_FOUND for both a missing component and a through-file walk; unix kernels report ENOTDIR natively, which std carries as ErrorKind::NotADirectory). The re-derivation walks the node's proper ancestors deepest-first (plain paths via fs::metadata, anchor roots via cumulative-prefix fstatat): the first ancestor that stats as a non-directory is where the walk died (ENOTDIR, synthesized in the portable ErrorKind form — no libc:: naming); an existing directory ancestor means the missing component is genuinely absent and the raw ENOENT stands.

Both cp operand gates (source cannot stat and multi-source target) now print the classified error through posix_errors::message, the same rendering the family's other tools (rm/touch/cat) already used — which is why they measured SAME in the probe round and this one did not.

Evidence

Three-way probe (GNU coreutils 9.4 / base f6e8c674 / this head), 22 shapes over the whole emulated file-builtin family — the through-file shapes flip to GNU-identical, every conservation shape is byte-identical before and after: cp plain/-r/deep/target (ENOTDIR), plain-missing stays ENOENT, rm/rm -f/touch/cat unchanged, mv/ln/install/stat are not rubash-emulated (real binaries; SAME by construction). Regression pin tests/issue3416_cp_stat_classification.rs (5 tests): the two through-file tests fail on base, all five pass on head; neighbour pin issue3276 stays 19/19; lib failure name-set empty.

One measured sibling is deliberately NOT folded into this PR: the same probe round found the emulated chmod's apply arm discards its metadata error the same way (chmod 600 a/b prints the ENOENT text on base and on this head). chmod does not consume CpNode — it is a separate call chain with its own mode-store semantics — so it is filed as #3425 with the full probe evidence for its own lane, rather than widening this PR's surface.

本 PR 删除了什么

Nothing — no code or tests removed; two hardcoded diagnostic strings are replaced by the classified rendering and the exists() gates by stat gates at the same two sites.

The emulated cp gated both operand stats on the boolean
CpNode::exists() and printed a hardcoded ENOENT text for every
failure, so a source (or multi-source target) spelled through a
regular file — whose walk dies ENOTDIR at the non-directory
component, the verdict coreutils copy.c reports from the stat
errno — came out as 'No such file or directory'.

CpNode::stat_classified keeps the stat's own error and
re-derives the verdict for a bare NotFound (the Windows face
answers ERROR_PATH_NOT_FOUND for both shapes): the deepest
existing proper ancestor decides, non-directory = ENOTDIR,
directory = the absence is genuine. Both cp gates now render
the classified error through posix_errors::message, the
rendering rm/touch/cat already used.

Regression: tests/issue3416_cp_stat_classification.rs
(through-file source/target fail on base, all pass on head;
missing operands stay ENOENT; family faces conserved).
@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain review — PASS (dossier: review-3426/CAPTAIN-VERIFY.md)

What was verified, and how:

  • Probe matrix re-run by the captain (22 shapes, GNU coreutils 9.4 oracle, lane's base/head binaries from hash-verified trees): at head every cp shape is byte-identical to GNU; the gnu-vs-head diff is exactly 3 lines — chmod s18 (filed as [bug] Simulated chmod stat classification: intermediate non-directory reported as ENOENT instead of ENOTDIR #3425, see below), mkdir s21 (locale quote glyphs only, class matches), mkdir s22 (the known naming difference on fix(executor): name the first failing component in simulated mkdir -p diagnostics #3389's face). On base the diff is those 3 + the 5 cp bug shapes. mv / rm / rm -f / rm -r / touch / cat cells are byte-identical to GNU on both columns.
  • Pins re-executed by the captain: issue3416 5/5, issue3276 19/19 on head. Base top-up fail-first read from the primary log: 3 passed / 2 failed, failures exactly cp_through_file_source_stat_is_enotdir + cp_through_file_target_is_enotdir.
  • Lane logs read directly, not relayed: lib 1246 passed / 0 failed (name-set ∅); full-target RUSTFLAGS="-D warnings" forced recheck = 1505 flagged rustc invocations, 0 errors; fmt / marker-literal / UTF-8 hygiene rc=0.
  • Intersection: merge-base f6e8c674; master has since advanced one commit (parser: backquote groups are opaque to the raw procsub word scans (Refs #3337) #3351, parser face) — interval intersection with this PR is ∅.
  • CI: finished and fully green on this head, including GNU goldens (7m54s), both cross-target checks, macOS and Windows compile legs.

Two notes for the record:

  1. The diff does add libc::S_IFMT/S_IFDIR — inside the #[cfg(unix)] At-root arm, next to the existing cp_fstatat machinery; the synthesized ENOTDIR itself is the portable ErrorKind form and no libc name reaches shared/Windows code. The finished darwin + linux/android cross-target legs cover this surface.
  2. The owed issue3333 leg is genuinely un-runnable on this tree (the pin lives on fix(executor): name the first failing component in simulated mkdir -p diagnostics #3389's branch and asserts its mkdir changes). The two PRs touch the same file in textually disjoint regions (verified hunk-by-hunk). Merge condition: whichever of fix(executor): name the first failing component in simulated mkdir -p diagnostics #3389 / fix(executor): classify emulated cp operand stat errors by the path walk #3426 lands second, its merged head runs issue3333 18/18 + issue3416 5/5 together.

#3425 delimitation confirmed independently: the chmod cell is wrong identically on base and head, and chmod's apply arm is a separate call chain that does not consume CpNode — it stays its own issue.

Environment note: the old server was banner-dead for most of this review window, so the captain's legs ran on the box against the lane's hash-verified trees (file hashes match the PR head byte-for-byte) instead of the planned server trees; the server-side driver bundle is staged at ~/work/r3426/ and its logs, if the queued run completes, should be spot-read at the merge round.

Ready to merge under the conditions in the dossier §9 (draft → ready, merge-body with the deletion section as drafted, closing-word scan clean: sole Fixes #3416).

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 12, 2026 12:14
@caomengxuan666
caomengxuan666 merged commit 685ccbc into master Nov 12, 2026
11 checks passed
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.

[bug] Simulated cp stat classification: intermediate non-directory reported as ENOENT instead of ENOTDIR

1 participant