Skip to content

chmod: apply mode through the CpNode under a dead cwd (Refs #3448) - #3486

Merged
caomengxuan666 merged 1 commit into
masterfrom
fix/3448-chmod-apply-dead-cwd
Nov 15, 2026
Merged

caomengxuan666 merged 1 commit into
masterfrom
fix/3448-chmod-apply-dead-cwd

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #3448

根因

PR #3440(Refs #3425)让 node-stat anchor 正确分类 chmod 操作数 stat 错误,但 chmod apply 本体仍用字符串路径:external_chmod 的 unix apply 臂在 node.stat_classified() 成功后,又做 std::fs::metadata(&host) + std::fs::set_permissions(&host, ...),其中 host 是 session-cwd 字符串 + 操作数的拼接路径。dead cwd 下该路径在 dead 分量上死 ENOENT,于是 chmod 600 a 报 ENOENT、mode 永不落地——分类对了,apply 到不了文件。

修法

  • 新增 CpNode::set_mode_bits_checked(&self, mode: u32) -> io::Result<()>(#[cfg(unix)],src/executor/external_file_builtins.rs,紧贴 cp preserve 面已有的 set_mode_bits):At 节点走 fchmodat(dirfd, rel, mode, 0),Plain 节点走 std::fs::set_permissions;失败返回原样 errno。set_mode_bits 本身吞错误,chmod 的 apply 臂需要失败值来报诊断,故加 fallible 双生而非改其签名。
  • external_chmod unix apply 臂:classified Ok 后改调 node.set_mode_bits_checked(new_mode);失败时 failures += 1 并以 posix_errors::message 打印原样 errno(与 [bug] Simulated chmod stat classification: intermediate non-directory reported as ENOENT instead of ENOTDIR #3425 的 classified Err 臂同一诊断形)。classified Err 臂(ENOTDIR/ENOENT 分类)逐字未动;非 unix 臂逐字未动;apply_chmod_mode(只算新 mode)未动。
  • 回归钉 tests/issue3448_chmod_apply_dead_cwd.rs(#![cfg(unix)],5 格):v3 rename 构造(cd t; (cd ..; mv t t_gone),session 留在被改名 inode 里)——chmod 600 a / u+x a / 600 d/f 在 dead cwd 下落地(mode 600/744/600),a/b 仍报 ENOTDIR、nope 仍报 ENOENT,mode 不变。

GNU 锚点

coreutils 9.4 src/chmod.c:231(fts errno 原样上报);bash 侧 fork 的子进程继承目录 inode 作 cwd(execute_cmd.c execute_disk_command)。Oracle:v3 探针(probe-dead-cwd3.sh)以 GNU bash + coreutils 9.4 本轮重跑:m1 chmod 600 a/b rc 1 ENOTDIR、m2 chmod 600 a rc 0 mode 600、m3 chmod 600 nope rc 1 ENOENT,与钉期望逐字一致。Base(master 3745712)三落地格均红(rc 1 ENOENT、mode 不变)。

本 PR 删除了什么

无产品面删除。删除的是 chmod unix apply 臂里“stat 成功后再以字符串路径二次 stat + set_permissions”的旧路径(约 15 行),由节点方法 set_mode_bits_checked 的一次 fchmodat/set_permissions 替代;被删路径的“stat 刚成功又 ENOENT”竞态分支随之消失(失败现由 fchmodat 自身的 errno 直接报告)。

验证状态

UNVERIFIED-BY-CAPTAIN — 队长复核前未验证。已过:rustfmt(两触文件)、utf8-boundary-hygiene、marker-lint、GNU oracle 对拍。待复核轮:Linux 腿(新钉 stem fail-first + 修后 5/5、全量 lib 与 base 对齐、RUSTFLAGS="-D warnings" check)与 X299 Windows 腿(check + 新钉空编译)。本地写墙 EDQUOT 致工作树暂存 /tmp,见 REPORT。

REPORT:工作区根(写墙恢复后落 ~/workspace/fix-3448/REPORT.md,现暂存 lane 侧 /tmp/fix-3448-REPORT.md)。

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.
@caomengxuan666

Copy link
Copy Markdown
Member Author

车道验证腿进展(2026-11-13 09:5x CST,X299-2607 Windows):

  • cargo check --locked --lib --bins(RUSTFLAGS="-D warnings"):RC=0,本改动在 lib/bins 面无警告。
  • cargo check --locked --test issue3448_chmod_apply_dead_cwd(-D warnings):RC=0,新钉在 Windows 下编译通过(#![cfg(unix)] 空编译)。
  • rustfmt(两触文件):RC=0。
  • cargo check --locked --tests(-D warnings):RC=101,但唯一错误是既有文件 tests/issue1331_1334_signal_and_startup.rs:11 的 run_script 死代码——其唯一调用方 sigpipe_trap_fires 为 #[cfg(unix)],Windows 下函数无调用方。本分支未碰该文件(diff 仅两文件),属 base 上已有的 Windows-only 条件,非本 PR 引入,不在本 PR 范围内修。
  • X299 直连 GitHub 不通(curl HTTP 000):源码经 box→新服务器→隧道传上 X299(tarball 19,816,895 B,fc1ffe9 核实)。

Linux 腿(新钉 fail-first + 修后 5/5、全量 lib 与 base 对齐)本轮未跑成,卡点:本地写墙 EDQUOT、box 盘 100% 满(他仓树不得删)、老服务器 ssh 未恢复、新服务器无 Rust 工具链。钉与 REPORT 已落盘,Linux 腿留复核轮。

@caomengxuan666

Copy link
Copy Markdown
Member Author

CI 初核(2026-11-13 10:0x CST):本 PR 的 CI 红与 base 逐字相同,非本 PR 引入——

  • 失败 job:Rust tests、Rust tests (macOS)、GNU regression goldens and canaries;三者均在 Run Rust library tests 步失败,唯一红测为 api::consumer_tests::issue2875_input_procsub_child_runs_as_rubash_shell(consumer_tests.rs:2911,26 passed / 1 failed / 4 skipped)。
  • Base 提交 3745712 自身的 CI 运行(run 43324872483)失败同一批 job、同一测试、同一计数。属已知的 issue2875 缺 --bin rubash 前置条件格(AGENTS.md 2026-11-11 根因),非产品回归;本 PR 的钉 stem 在 CI 里尚未跑到(Run all regression pin stems 步被 skip),Linux 腿仍待复核轮实测。

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-AUDIT】

PR #3486 第1轮 — 建议:PENDING(缺腿)
head: fc1ffe9 base(merge-base): 3745712 文件: 2 个 +238/-15
关联 issue: #3448(状态:open,我核过的时间:本地当前)

机制核查:

  • 修复方向正确:stat 分类此前已用 dead-cwd CpNode 锚点,但 apply 路径把节点重拼成字符串路径再调 metadata/set_permissions,cwd 分量被 rename 后必然 ENOENT。新增 CpNode::set_mode_bits_checked:CpRoot::Plain 走 std::fs::set_permissions,CpRoot::At 走 libc::fchmodat(dirfd, relpath, mode, 0),chmod apply 臂直接上报节点操作的实际 errno——符合 GNU chmod 经由 fchmodat/openat 锚定目录 fd 的语义。
  • 无关改动:无(仅 external_file_builtins.rs + 新钉文件)。

腿(逐项):

  • 钉自跑:tests/issue3448_chmod_apply_dead_cwd.rs 为 #![cfg(unix)],Windows 本机编译进 stem 但 0 tests;CI 因 [test-harness] Input process-substitution child resolves its exe without the test-binary fallback #2875 fail-fast 未跑到该 stem;本腿未在任何平台执行过 → 缺腿。
  • fail-first:同上,未执行 → 缺腿。
  • lib 双边:head 失败名集 {issue2084_session_end_restores_host_process_state} / base(3745712) 失败名集 {issue2084_session_end_restores_host_process_state} / 差集 ∅(该失败为环境性基线,两树一致复现)。
  • -D warnings:命中既有无关警告 tests/issue2473_procsub_operand_marker_regressions.rs 的 use std::io::Write as _;(cfg windows 测试,base 同存),非本 PR 引入;本 PR 文件 0 警告。
  • 卫生:fmt 两个文件均 FMT-OK;marker-lint 通过;utf8 边界检查通过。
  • CI:红任务逐个归因——Rust tests / macOS Rust tests / GNU goldens 均为已知基线 issue2875_input_procsub_child_runs_as_rubash_shell(-c 前置条件,base CI 同红)→ 记「基线」;Windows checks / cross-target(linux/android) / API ledger / compat CLI / shell tests / niubash build / Windows compile 全绿。
  • GNU 对照:WSL GNU bash 5.3.20(/usr/local/bin/bash,脚本文件 LF)。dead-cwd 形状复跑:chmod 600 a/b → rc=1 'Not a directory';chmod 600 a → rc=0 mode=600;chmod 600 nope → rc=1 'No such file or directory';chmod u+x a2 → rc=0 mode=744;chmod 600 d/f → rc=0 mode=600。与钉断言的五种形状逐一吻合(脚本:target/probes-3486/oracle.sh)。Linux dead-cwd 语义 WSL 可复现(rename 后 cwd inode 仍活),但严格 Linux fchmodat 行为仍建议队长 Linux oracle 抽验。

F 点:无。

续作记录:未动代码。

未跑/VOID 的腿:

@caomengxuan666

Copy link
Copy Markdown
Member Author

【WIN-AGENT-REWORK】

PR #3486 第2轮 — 建议:PASS(缺腿补齐)
head: fc1ffe9(与审计一致,无人推进) base(merge-base): 3745712
关联 issue: #3448

本轮补腿(WSL Linux /root/rubash-wsl,CARGO_INCREMENTAL=0,cargo test --locked -j 2):

  • head fc1ffe9:cargo test --test issue3448_chmod_apply_dead_cwd → 5 passed / 0 failed(lands/nested/symbolic + ENOTDIR/ENOENT 两 diag 格全绿)。
  • base 3745712 + 钉 overlay:→ 2 passed / 3 failed。红集 = {chmod_apply_dead_cwd_lands, chmod_apply_dead_cwd_nested_lands, chmod_apply_dead_cwd_symbolic_lands},签名 chmod_rc=1(dead-cwd 重拼路径 ENOENT);两 diag 格双边绿(base 诊断面本就正确)。fail-first 精确命中修复面。

未动代码;其余腿按第1轮审计记录全绿。判词翻 PASS,按协议 squash 合并。

@caomengxuan666
caomengxuan666 marked this pull request as ready for review November 15, 2026 04:42
@caomengxuan666
caomengxuan666 merged commit 5dcd1e6 into master Nov 15, 2026
8 of 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.

1 participant