Repository navigation
Emulated mkdir/rm/touch: resolve operands through the cwd anchor under a deleted cwd - #3331
Merged
caomengxuan666 merged 4 commits intoNov 11, 2026
Merged
Conversation
…r a deleted cwd GNU bash has no mkdir/rm/touch builtin: execute_cmd.c:5771 execute_disk_command forks a child that inherits the session's cwd INODE, and the coreutils tool's relative operands are walked by the kernel from that inode. The emulated tools instead resolved every operand through the session-cwd string, which dies at the deleted component — escapes to the parent failed ENOENT, and once the path was recreated in place the string walked into the recreated ghost directory (rm deleted the ghost's files; mkdir -p even resurrected the deleted directory and built inside it). Each operand root now converges ONCE at the handler entry through the existing Executor::cp_operand_root (the convergence the emulated-cp face built on the identity verdict of the ghost fix) — no second gate. CpNode gains create_dir (mkdirat), remove_dir (unlinkat with AT_REMOVEDIR), remove_dir_all (a node walk that never follows symlinks) and stamp_existing (utimensat against an explicit dirfd; the existing touch stamp splits into that core plus its AT_FDCWD form). rm's guards read the same node: the dot/dotdot existence question is the node's stat, and preserve-root under an anchor root compares (dev, ino) identity where the string canonicalize cannot walk. touch's -r reference resolves through the same root. Plain roots keep the exact pre-face std calls, byte for byte. New pin stem tests/issue3276_simulated_tools_dead_cwd.rs: 19 cells (per-handler fail-first, regression locks, a live-cwd control). On the base the stem reads 6 passed / 13 failed with the red set exactly the defect cells; with this change 19/19.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Refs #3276
背景
#3268 家族普查(设计卷宗
fix-3268-ade/DESIGN.md§6.1)在 mastera78f0cde实测:进程内模拟 mkdir / rm / touch 在已删 cwd 下与模拟 cp 同红——操作数一律经会话 cwd 字符串拼接解析,死分量处断裂。本 PR 在现 master5d8867fd(含 (d) 收敛层)上重新探针定界:19 格探针中 13 格与 GNU 分叉,含三处硬伤——mkdir -p ../pdir/deep把已删目录复活并建在其下、rm marker在目录被原地重建后删掉了幽灵目录的文件、touch marker同形穿越盖戳。GNU 锚
GNU bash 不实现 mkdir/rm/touch:
execute_cmd.c:5771 execute_disk_commandfork 出的子进程继承 cwd inode,coreutils 工具的相对操作数由内核自该 inode 行走。本 PR 的 oracle = GNU bash 5.3.20 + 系统 coreutils 逐格实测(探针与双边日志随车道卷宗存档):逃逸父级成功、向死目录内创建/删除由内核 ENOENT 裁决、幽灵不穿越。修法(机制级,复用既有收敛层,不另起门)
Executor::cp_operand_root((d) 面所立)收敛一次为CpNode根:相对操作数 + 会话 cwd 不可解析(删后原地重建目录的幽灵穿越:静止会话经复活路径读到新目录内容(GNU 仍坐死 inode 报 ENOENT) #3275 身份判词)+ 锚命名该 cwd → 锚相对根;其余一切形状保持 Plain 拼接串逐字节不变。CpNode新增四个节点方法,全部 Plain 臂 = 现行 std 调用原样、At 臂 = *at 族对锚句柄操作:create_dir(mkdirat)、remove_dir(unlinkat + AT_REMOVEDIR)、remove_dir_all(节点递归,符号链接不跟随)、stamp_existing(utimensat 的 (dirfd, rel) 形;既有touch_utimensat拆出同一核心,AT_FDCWD 形为其特例)。create_dir、-p走既有create_dir_all节点形。./..拒绝护栏的存在性判定全走节点 stat;preserve-root 在锚根操作数下改以 (dev, ino) 身份比较(字符串 canonicalize 穿不过死分量),Plain 操作数保持原字符串判词原样;删除分发走remove_file/remove_dir/remove_dir_all节点形。-r参考文件同为路径入参,一并经同一根收敛读其 atime/mtime。钉
新茎
tests/issue3276_simulated_tools_dead_cwd.rs,19 格(逐处理器 fail-first + 回归锁 + 活 cwd 对照)。基底5d8867fd上 fail-first:6 过 / 13 红,红集恰缺陷格(mkdir 逃逸/-p 复活/-p 入死/幽灵、rm 逃逸/树逃逸/无 -r 侧别/dotdot 护栏/幽灵、touch 逃逸创建/逃逸盖戳/参考逃逸/幽灵)。改后数字见车道报告。本 PR 删除了什么
无删除。本 PR 为纯新增节点方法与处理器接线:
touch_utimensat的函数体拆为 (dirfd, rel) 核心 + AT_FDCWD 薄封装,属同函数内重构,原调用点签名不变;无文件、无公开面、无既有行为面被删除。