Skip to content

fix(executor): name the first failing component in simulated mkdir -p diagnostics - #3389

Merged
caomengxuan666 merged 4 commits into
unixwin:masterfrom
Uarz:fix/issue-3333
Nov 12, 2026
Merged

caomengxuan666 merged 4 commits into
unixwin:masterfrom
Uarz:fix/issue-3333

Conversation

@Uarz

@Uarz Uarz commented Nov 11, 2026

Copy link
Copy Markdown
Member

Fixes #3333

What was fixed

Simulated mkdir -p a/b printed the whole operand ('a/b') when a was a file; GNU prints the first failing component ('a').

Root cause: the -p branch called node.create_dir_all() (Plain arm: std::fs::create_dir_all; At arm: a hand-rolled mkdirat walk), which returns a bare io::Error with no failing component, so the diagnostic could only print the operand. The fix replaces the -p branch with mkdir_create_parents, a per-component walk structured like GNU coreutils make_ancestors: each textual prefix is created with the same root resolution as the whole operand (shell_path_to_windows → session_path → cp_operand_root, still the #3276 cwd-anchor route in a deleted cwd), one single create_dir per prefix (mkdirat on the At arm, fs::create_dir on Plain); after EEXIST a follow-stat decides — directory → continue, non-directory → ENOTDIR, stat failure (dangling symlink) → keep the original EEXIST. Failures return (io::Error, the prefix's original spelling), and the diagnostic prints that prefix. mkdir_parent_prefixes slices the operand's original text on / (a/b → ["a","a/b"], a/./b → ["a","a/.","a/./b"], a//b → ["a","a//b"]), keeping literal separators; cuts land on / bytes so there is no UTF-8 split issue. The single-dir branch is untouched (still names the operand), plus a same-family empty-operand guard: mkdir "" used to answer EEXIST against the session cwd, now GNU's ENOENT (mkdir -p "" went from rc 0 to ENOENT). CpNode::create_dir_all is untouched (cp -r still uses it). A survey of cp/mv/rm found no same disease: their simulated diagnostics already name the actually-failing path, and only mkdir -p does a per-component walk.

Specification note: this one's spec is GNU coreutils mkdir.c make_ancestors, not the bash submodule (which only holds bash). Expectations are from system GNU coreutils 9.4 /usr/bin/mkdir measurements (16 probed shapes, spelling preserved verbatim: ./a/b → './a', a/./b/c → 'a/./b', a//b/c → 'a//b', ../x/y → '../x', absolute paths, dangling-symlink components keep EEXIST, multi-operand continues after a failure with rc 1).

What was deleted

Nothing. No files, features, or tests were removed. One comment in tests/issue3276_simulated_tools_dead_cwd.rs was updated (its "mkdir -p prints the operand in rubash" example no longer holds after this fix).

Verification (all run, per-item counts)

  • Regression pin tests/issue3333_mkdir_p_failing_component_name.rs: 18/18 pass (stderr asserted word-for-word, rc and landing points asserted alongside). Fail-first on the unpatched tree (supervisor re-ran with the patch method): 6 passed / 12 failed — exactly the 12 divergence faces were red (first component, second component, deleted cwd, empty operand ×2, ./, /., //, absolute path, ../, multi-operand, dangling multi-level); the 6 green cells are controls/conservation (single-dir operand name, mkdir -p ., /, success chain, symlink-to-directory, dangling single level).
  • Adjacent: issue3276_simulated_tools_dead_cwd 19/19, issue1372_chmod_mkdir_redirect_regressions 1/1, issue555_file_builtin_family_regressions 11/11, issue3268_cp_anchored_operands 10/10, issue615_copy_contents 4/4 (supervisor re-ran issue3276 and issue555).
  • cargo build -j 2 clean, cargo fmt --check clean. src/lexer/continuation.rs untouched.

Owed

  1. Windows unverified: prefix slicing only splits on /; a backslash-separated operand degrades to a single prefix on Windows (same as pre-fix behavior, no regression). No Windows environment on this machine to test with.

… diagnostics

Simulated 'mkdir -p a/b' printed the whole operand ('a/b') when 'a' was a file; GNU prints the first failing component ('a'). Root cause: the -p branch called node.create_dir_all() (Plain: std::fs::create_dir_all; At: a hand-rolled mkdirat walk), which returns a bare io::Error with no failing component, so the diagnostic could only print the operand. The fix replaces the -p branch with mkdir_create_parents, a per-component walk structured like GNU coreutils make_ancestors: each textual prefix is created with the same root resolution as the whole operand (shell_path_to_windows -> session_path -> cp_operand_root, still the unixwin#3276 cwd-anchor route in a deleted cwd), one single create_dir per prefix (mkdirat on the At arm, fs::create_dir on Plain); after EEXIST a follow-stat decides: directory -> continue, non-directory -> ENOTDIR, stat failure (dangling symlink) -> keep the original EEXIST. Failures return (io::Error, the prefix's original spelling), and the diagnostic prints that prefix. mkdir_parent_prefixes slices the operand's original text on '/' (a/b -> ['a','a/b'], a/./b -> ['a','a/.','a/./b'], a//b -> ['a','a//b']), keeping literal separators; cuts land on '/' bytes so there is no UTF-8 split issue. The single-dir branch is untouched (still names the operand), plus a same-family empty-operand guard: 'mkdir ""' used to answer EEXIST against the session cwd, now GNU's ENOENT (mkdir -p '' went from rc 0 to ENOENT). CpNode::create_dir_all is untouched (cp -r still uses it). A survey of cp/mv/rm found no same disease: their simulated diagnostics already name the actually-failing path, and only mkdir -p does a per-component walk.

Refs unixwin#3333

Regression pin tests/issue3333_mkdir_p_failing_component_name.rs (18 tests; fail-first 6 passed / 12 failed on the unpatched tree, 18/18 pass after; supervisor verified both rounds with the patch method). Expectations are from GNU coreutils 9.4 /usr/bin/mkdir measurements (16 probed shapes; the spec is coreutils mkdir.c make_ancestors, not in the bash submodule). Adjacent: issue3276 19/19, issue1372 1/1, issue555 11/11, issue3268_cp 10/10, issue615 4/4 (supervisor re-ran issue3276 and issue555). cargo fmt clean. Also updated one comment in tests/issue3276_simulated_tools_dead_cwd.rs whose 'mkdir -p prints the operand in rubash' example no longer holds after this fix.
@caomengxuan666 caomengxuan666 self-assigned this Nov 11, 2026
@caomengxuan666 caomengxuan666 added bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做 area:path path model, command lookup, drive/POSIX spellings, argv translation labels Nov 11, 2026
@caomengxuan666

Copy link
Copy Markdown
Member

Thanks for the PR. This is queued for captain review — collaborator PRs are reviewed by the captain before merge, and #3333 stays open until that review lands.

CI at intake: not green — 2 Windows legs fail, and the failure is in this PR's new code. Both failing legs report the same error[E0433]: cannot find module or crate 'libc' at src/executor/external_file_builtins.rs:450, :468, and :586 — the new mkdir_create_parents and the empty-operand arm use libc::ENOENT / libc::ENOTDIR in shared (non-cfg-gated) code, while every existing libc:: use in that file sits inside #[cfg(unix)] items and there is no unconditional use libc;. Linux/macOS legs all pass, so this is a Windows-only compile break introduced here; the fix direction is to build those errors without libc:: in shared code. Everything else looks sound on first pass: pin 18/18 fail-first (6 passed / 12 failed on the unpatched tree, exactly the 12 divergence faces), and the Windows leg is the only thing standing between this PR and review. No merge action from the captain until the Windows legs are green.

@caomengxuan666

Copy link
Copy Markdown
Member

2026-11-12 用户令:不等作者修 Windows 面,队长接手。E0433(共享代码 libc::ENOENT/ENOTDIR 无无条件导入)由队长车道按仓内先例修(可移植判定口径),windows-gnu check 验过后回队长复核队列走完整复核。作者原提交全部保留。

…n shared code)

The unixwin#3333 change built its fabricated ENOENT/ENOTDIR errors with
io::Error::from_raw_os_error(libc::ENOENT / libc::ENOTDIR) in shared
code, but external_file_builtins.rs has no unconditional libc import
— every other libc:: use in the file sits inside #[cfg(unix)] items —
so both Windows CI legs failed with E0433 (cannot find crate libc).

Construct the three errors the crate's established portable way,
io::Error::new(kind, GNU strerror text), as in
command_input_scope.rs and shell_options.rs: kind() is unchanged
(NotFound / NotADirectory — the kinds std maps errno 2 / 20 to), and
posix_errors::message renders byte-identical text, since the
raw-code table's strings for those codes and the literal payloads
agree. No cfg fallback constants.

Captain takeover commit on the author's branch (2026-11-12 order);
the author's commits are untouched.
@caomengxuan666

Copy link
Copy Markdown
Member

Captain review of head 2d3ffa8e (your commit plus the captain takeover commit for the Windows compile fix): FAIL — one rework commit needed, folded into this PR. Everything on the Unix face passes and your declaration reconciles exactly; the single blocker is a conservation break in the new walk on the simulated (Windows) face, caught by this head's own golden leg.

What passed (captain re-ran all of it on the box)

  • Pin issue3333_mkdir_p_failing_component_name: 18/18 on head; on the real merge-base f5f65d35 with the pin topped up, 6 passed / 12 failed, the 12 red names exactly your declared divergence faces.
  • Adjacent stems exactly as declared: issue3276 19/19, issue1372 1/1, issue555 11/11, issue3268 10/10, issue615 4/4. Lib failure name-sets empty on both sides (1245 passed each).
  • Three-way probes (GNU coreutils 9.4 / base / head, 17 mkdir shapes covering the issue's whole delimitation): head byte-identical to GNU on all 17, including the deleted-cwd shape ('inner' + ENOENT + no resurrection).
  • Hygiene: fmt / UTF-8 / marker-lint clean; -D warnings shows no error in any file this PR touches (the one full-target error is a pre-existing dead field in tests/issue2702_…, byte-identical on the base tree — not yours, no action).
  • Takeover commit verified: exactly the 3 libc:: sites, and the classification-equivalence chain holds (sole consumer renders through posix_errors::message; errno-table text and the io::Error::new payloads are byte-identical). The Windows compile leg is green on this head, as are darwin / linux-android.

The blocker — goldens leg is red on this head, in your mechanism

GNU regression goldens and canaries, cargo test --test regression: 233 passed / 1 failed. The one failure is golden_nvm_load: golden stderr is empty, actual adds

mkdir: cannot create directory '/c': Permission denied

The truncated prefix name can only come from the new walk. Mechanism: mkdir_create_parents treats only EEXIST as "component may already exist". On the simulated face, a bare create_dir on an already-existing component — above all a drive/root prefix like /c — can answer EACCES instead, and the walk then aborts with a diagnostic where the old create_dir_all (and GNU -p's observable contract: every existing component is success) was silent. Blast radius: any mkdir -p with an absolute/root-prefixed operand on the Windows face; relative operands and Unix are unaffected (hence the all-green Unix evidence above).

Required rework (one commit on this branch)

In mkdir_create_parents, align the existence test with the -p contract: on any create_dir error, follow-stat the prefix —

  • stat shows a directory → continue the walk (covers both EEXIST and EACCES answers);
  • stat shows a non-directory → ENOTDIR diagnostic naming the prefix (same text as the current EEXIST arm);
  • stat itself fails → return the original create error (this keeps the dangling-symlink EEXIST cells and genuine-error shapes exactly as they are).

The 18 pin expectations must not change — on Unix the new rule is cell-for-cell equivalent to the old one (an existing directory always answers EEXIST there), so any pin edit means the rework has drifted. The regression lock for the Windows shape is golden_nvm_load itself (the shape is not constructible on Unix); please name that cell in the rework commit message. On the new head I will re-check: goldens leg finished green (hard gate), pin 18/18, issue3276 19/19, and the 17-shape probe set.

Two non-blocking notes

  1. Your cp/mv/rm survey sentence needs one correction: for cp -r a/b dest with a a regular file, GNU prints cp: cannot stat 'a/b': Not a directory while rubash prints …: No such file or directory — the name is right, the error classification is not. This is byte-identical on the base tree (pre-existing, not caused by this PR); the captain will file it separately — no action here. mv/rm on the same shape match GNU exactly.
  2. Owed 1 (backslash-separated operands degrading to a single prefix on Windows) stands as declared — same as pre-fix behavior, out of scope here.

The takeover commit stays as-is; the rework goes on top of it. #3333 stays open until the reworked head clears the goldens gate.

… only EEXIST

Captain rework on the author's branch (captain review of PR unixwin#3389,
section 7.1), folding the head-CI goldens failure into this PR.
The -p component walk treated only EEXIST as "possibly already
exists", but on the simulated (Windows) face a bare create of an
already-existing component — a drive root such as `/c` above
all — can answer EACCES instead, so `mkdir -p` aborted with
`mkdir: cannot create directory '/c': Permission denied` where
GNU -p succeeds silently. That is the CI goldens failure in
`golden_nvm_load` (nvm's load path mkdir -p's a drive-rooted
operand).

The walk now follow-stats the prefix after any create failure,
not just EEXIST: a directory continues the walk, a non-directory
is ENOTDIR naming the prefix, and a stat failure returns the
original create error (a dangling symlink keeps GNU's EEXIST; a
genuine failure keeps its own errno). No operand-text special
cases; the decision sits at the walk's single point.

On unix an existing component always answers EEXIST, so the
widened trigger is observably identical there and no unix
expectation changes: pin issue3333 stays 18/18 and issue3276
stays 19/19. The Windows shape has no unix-constructible form
(the kernel answers EEXIST first); its regression lock is the
goldens `golden_nvm_load` cell itself, named here per the
review's rework terms.
caomengxuan666 added a commit that referenced this pull request Nov 12, 2026
…alk (#3426)

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

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); 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.

## 本 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.

## 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.

## Verification (captain review)

- Captain verdict PASS (`~/workspace/review-3426/CAPTAIN-VERIFY.md`): probe table and both pin binaries independently re-executed by the captain (cp face diff vs GNU = ∅ at head; pins 5/5 and 19/19); lane primary logs read directly (base top-up fail-first = exactly the two through-file names; lib 1246/0; full-target `-D warnings` forced recheck 1505 flagged invocations, 0 errors; fmt/marker-literal/UTF-8 hygiene rc=0). Old-server legs were displaced by the server's sshd banner outage during the review window; the finished CI on this head is fully green including GNU goldens, both cross-target checks, macOS and Windows compile legs.
- Merge obligation carried from the lane report: whichever of this PR and PR #3389 (same file, textually non-overlapping regions) lands second, its merged head must run issue3333 (18/18) + issue3416 (5/5) together.
@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 12, 2026 12:43
@caomengxuan666
caomengxuan666 merged commit 94c5dd9 into unixwin: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

area:path path model, command lookup, drive/POSIX spellings, argv translation bug Something isn't working gnu-baseline Tracked by the GNU Bash 5.3.0 true-baseline ledger P3-low 低:优化、文档、远期规划,有机会再做

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[bug] simulated mkdir -p diagnostic names the whole operand instead of the first failing component

2 participants