Skip to content

fix(executor): classify emulated chmod operand stat errors by the path walk (Refs #3425) - #3440

Merged
caomengxuan666 merged 2 commits into
masterfrom
fix/3425-chmod-stat-class
Nov 12, 2026
Merged

caomengxuan666 merged 2 commits into
masterfrom
fix/3425-chmod-stat-class

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3425 — UNVERIFIED-BY-CAPTAIN

根因

模拟 chmod 在 apply 臂里丢弃了操作数 metadata 的错误,对一切失败都印硬编码 ENOENT 文本:chmod 600 a/b(a 为普通文件)报 No such file or directory,而 GNU 报路径行走的 ENOTDIR。

GNU 锚点

GNU coreutils 9.4 src/chmod.c:231:error (0, ent->fts_errno, _("cannot access %s"))——fts 行走的 errno 原样输出;行走死在第一个非目录分量上即 ENOTDIR。本地 oracle 实测(probe-3425.sh,12 形,~/workspace/fix-3425/probe-3425.gnu.txt):a/b、a/b/c、a/b d、f1 f2 a/b、+x a/b、a/ 皆 Not a directory;missing、missing/sub、d/missing 皆 No such file or directory;a、d/f、d 皆 rc 0 且 mode 落 600。

修法

操作数 stat 走 CpNode 机制(external_cp 同款根:cp_operand_root——死 cwd 下为锚相对根,其余为 plain joined path),apply 臂失败用 CpNode::stat_classified + posix_errors::message 渲染;符号子句的 base mode 与 is_dir 同样取自 node stat。行走死在非目录分量上报 ENOTDIR,真正缺失的分量保持 ENOENT。锚面或竞态下 node stat 已成而内层 metadata 失败时,保留 raw verdict 不分类(旧行为)。

同 #3416 的机制(CpNode::stat_classified),推广到 chmod 的 plain host path;cp 的两道门未动。未碰 src/lexer/continuation.rs,未改 docs/api-ledger.md,未引入任何 trust/签名/加载期校验机制。

测试

新钉 tests/issue3425_chmod_stat_classification.rs(6 tests,覆盖 12 个探针形;stderr 字节 + rc + 落盘 mode):

  • chmod_through_file_reports_enotdir(a/b、a/b/c)
  • chmod_through_file_multi_operand_reports_enotdir(a/b d、f1 f2 a/b)
  • chmod_missing_operands_stay_enoent(missing、missing/sub、d/missing)
  • chmod_plain_operands_still_land(a、d/f、d 落 600)
  • chmod_symbolic_mode_through_file_reports_enotdir(+x a/b)
  • chmod_file_trailing_slash_reports_enotdir(a/)

Fail-first 预期:base 2/6 过(仅两守恒 tests),head 6/6。本地腿未跑:本机无 cargo、本轮 box 构建槽已满(盘 1.8G 空、Mem 1.66G),按简报先推草稿 PR、以 CI 编译为首道验证;钉双边/lib/-D warnings/卫生全腿待队长复核轮上 X299/box 跑。cargo fmt --check 本地亦无法跑(无工具链),改动按文件既有格式手写;CI fmt 腿为准。

本 PR 删除了什么

无删除。本 PR 只改一处 chmod 操作数 stat 路径并新增一支回归钉:无文件删除、无公开 API 删除、无行为删除;唯一行为变化是诊断错误类按 GNU 订正(经普通文件的操作数由 ENOENT 改为 ENOTDIR,缺失操作数保持 ENOENT)。

…h walk (Refs #3425)

The emulated chmod discarded the operand metadata error in its
apply arms and printed a hardcoded ENOENT text for every failure,
so `chmod 600 a/b` (a a regular file) reported 'No such file or
directory' where GNU coreutils reports the walk's ENOTDIR.

Route the operand stat through the CpNode machinery (the same root
external_cp builds via cp_operand_root) and render the apply-arm
failure with CpNode::stat_classified + posix_errors::message:
a walk that dies at a non-directory component reports ENOTDIR,
a genuinely missing component keeps ENOENT. The base mode and
is_dir for symbolic clauses now come from the node's stat as well.

GNU anchor: coreutils 9.4 src/chmod.c:231 — error (0,
ent->fts_errno, 'cannot access %s'), i.e. fts's walk errno
verbatim. Regression pin tests/issue3425_chmod_stat_classification.rs
(6 tests, 12 probe shapes; base is expected 2/6, head 6/6 —
legs not run on this lane, see REPORT; CI is the first check).

UNVERIFIED-BY-CAPTAIN
@caomengxuan666

Copy link
Copy Markdown
Member Author

Captain review — PASS

Reviewed at head 738735e4b843aeb851c4638623f76b43af9a94f1; true fork point 52eee03f (git merge-base). All legs ran on the Simular box (X299 lane use still pending the key-auth decision; box was the briefed fallback). Full dossier: ~/workspace/review-3440/CAPTAIN-VERIFY.md.

Measured

  • Pin issue3425_chmod_stat_classification: 6/6 on the head; on the fork base with only the pin topped up, 2 passed / 4 failed, the failures exactly the four ENOTDIR tests (per-name fail-first, matching the lane's predicted 2/6).
  • Adjacent stems unchanged on head: issue3276_simulated_tools_dead_cwd 19/19, issue3416_cp_stat_classification 5/5, issue3333_mkdir_p_failing_component_name 18/18.
  • lib bilateral: 1246 passed / 0 failed / 4 ignored on both trees, failure name sets identical (empty).
  • Three-way probes (12 shapes; GNU coreutils 9.4 oracle, fork base, this head): the head matches GNU byte-for-byte on every shape — the only diff lines are the probe harness's own teardown rm lines, which differ solely in the mktemp -d random suffix. GNU-vs-base differs in exactly the 6 bug shapes. GNU anchor re-verified by the captain: coreutils 9.4 src/chmod.c:231 is exactly error (0, ent->fts_errno, _("cannot access %s"),.
  • Dead-cwd extra probes (captain-designed, rename construction): chmod 600 a/b reports ENOTDIR on head vs ENOENT on base — the anchor node stat works; chmod 600 a fails ENOENT on both (apply residual, see below).
  • Warnings: full-target -D warnings forced recheck (all tests/*.rs touched, -v): 1510 flagged rustc invocations, 0 errors; the pin crate itself was rechecked with -D warnings. fmt, marker-literal and UTF-8 boundary hygiene legs clean.
  • Head CI: finished, 10 success + 1 skipping, zero failure.

Delimitations attached to this review

Merge conditions

Update-branch first (master moved to c28a9dd during review; recheck the §0 intersection on the then-live tip — expected ∅), then on the merged head: pin 6/6, lib failure set ∅, adjacent stems unchanged, full-target -D warnings with 0 errors, merged-shape spot checks, final-head CI finished green.

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 12, 2026 16:03
@caomengxuan666
caomengxuan666 merged commit f831386 into master Nov 12, 2026
11 checks passed
caomengxuan666 added a commit that referenced this pull request Nov 15, 2026
…3486)

The node-stat anchor from #3440 classifies the operand correctly,
but the apply arm then re-stats and chmods through the joined
string path, which dies ENOENT on the dead cwd component even
though the node stat just succeeded. Apply through the node
instead (CpNode::set_mode_bits_checked: fchmodat against the
anchor for an At node, set_permissions for a Plain node), the
walk GNU's forked child gets (coreutils 9.4 chmod.c:231).

Regression pins in tests/issue3448_chmod_apply_dead_cwd.rs cover
the v3 probe cells: chmod 600 a / u+x a / 600 d/f land under a
dead cwd, a/b still reports ENOTDIR, nope still ENOENT.

Co-authored-by: 曹梦轩 <[email protected]>
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.

1 participant