Skip to content

fix(tree/namei/look): fold POSIX drive-dialect operands onto the named drive (#1236 #1237 #1242) - #1248

Merged
caomengxuan666 merged 4 commits into
mainfrom
fix/1236-1237-1242-drive-dialect
Oct 19, 2026
Merged

caomengxuan666 merged 4 commits into
mainfrom
fix/1236-1237-1242-drive-dialect

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Second wave of the #1230 drive-dialect audit repairs, following the merged #1243 (mkdir/ln) and #1245 (canonicalize_path_w) precedents. Three read-side commands still handed raw POSIX drive spellings to Win32, which resolves a leading /e against the current drive - so the command answered for a cwd-drive shadow instead of the named path. Fixes #1236, #1237, #1242.

Root cause and fix (same boundary as #1243/#1245)

/cygdrive/e, /mnt/e and bare /e share the fold (single-sourced by fold_drive_dialect_w, #1145/#1172/#1231).

Live matrix (PowerShell native argv; fixture E:\probe-wb built for the run and removed after; MSYS ls/cat confirm the dialect resolves to E:\probe-wb)

Probe (PS native argv) cwd=C:\ before cwd=D:\ before cwd=C:\ after cwd=D:\ after
tree -L 2 /e/probe-wb cannot access 'C:\e\probe-wb' cannot access 'D:\e\probe-wb' lists E:\probe-wb (3 files) lists E:\probe-wb
tree -L 1 /e (bare root) cannot access 'C:\e' cannot access 'D:\e' lists E:\ root lists E:\ root
tree -L 2 /cygdrive/e/probe-wb cannot access 'C:\cygdrive\e\probe-wb' same on D: lists E:\probe-wb lists E:\probe-wb
tree -L 2 /mnt/e/probe-wb cannot access 'C:\mnt\e\probe-wb' same on D: lists E:\probe-wb lists E:\probe-wb
tree -L 2 E:/probe-wb (control) OK OK OK OK
namei /e/probe-wb/probe-marker.txt f e (No such file or directory) same chain d E:\\ -> d probe-wb -> f probe-marker.txt same
namei /e (bare root) f e (No such...) same d E:\\ d E:\\
namei /cygdrive/e/probe-wb, namei /mnt/e/probe-wb f cygdrive/f mnt broken same full chain full chain
look -f 2026 /e/probe-wb/probe-marker.txt cannot open '/e/...' same prints the marker line same
look -f ... /cygdrive/e/..., /mnt/e/... dict cannot open same matched line matched line
look -f alp E:/probe-wb/dict-sorted.txt (control) OK OK OK OK
tree /e/probe-wb/absent-dir (missing) - - cannot access '/e/probe-wb/absent-dir' (operand spelling kept) same
namei /e/probe-wb/absent-child (missing) - - chain resolves, then f absent-child (No such file or directory) same
look -f 2026 /e/probe-wb/absent.txt (missing) - - cannot open '/e/probe-wb/absent.txt' (operand spelling kept) same

Shadow witnesses C:\e, C:\d, D:\e were False before, after, and between every probe batch (tree/namei/look are read-only; the probes never create anything).

Tests

  • tests/unit/tree: 5 new regressions (dialect lists operand drive; cygdrive+mnt; bare-drive root; foreign-cwd negative; error quotes operand spelling).
  • tests/unit/namei/: new file, 6 regressions (dialect chain resolves; bare drive root; cygdrive/mnt; foreign-cwd; missing component still reports; native form unchanged).
  • tests/unit/look/: new file, 5 regressions (dialect opens; cygdrive+mnt; foreign-cwd; error quotes operand spelling; native form unchanged).
  • All dialect spellings are synthesized from the TempDir's own drive (mkdir/fix(mkdir,ln): fold POSIX drive-dialect operands before any write (#1233, #1234) #1243 pattern), so the tests pass on any host; a foreign-cwd negative runs only when a second fixed drive exists.

Local: scripts/build.py (MSVC + CMake + vcpkg) builds clean; ctest: 3013/3020 in one full parallel run, the 7 failures (ls/mktemp/timeout/wc/which/wpm x2) all pass on isolated retry - concurrent-run flakes, untouched by this branch; all 27 tree/namei/look tests green.

Adjacent defect noticed, out of scope

look's line reader turns a trailing newline into an empty final line, which can skew the binary search's lower bound past the last real entry (e.g. -f delt against alpha\nbravo\ncharlie\ndelta\n prints nothing even on a plain Windows path). Pre-existing, unrelated to the dialect fold - worth its own issue.

tree handed the raw root operand ('/e/Data', '/cygdrive/e/Data',
'/mnt/e/Data') to GetFullPathNameW, and Win32 resolves a leading '/e'
against the CURRENT drive: from a C: cwd 'tree /e/Data' rejected a
directory that exists on E: - or silently listed the shadow 'C:\e\Data'
where one happened to exist, the cwd-drive-drift form from the #1230
sweep. A bare '/e' listed or rejected '<cwd>:\e' the same way.

The operand now folds once through the shared normalize_api_operand
boundary before any Win32 call; the verbatim spelling is kept apart so
the 'cannot access' message quotes what the user typed instead of the
folded native form, like MSYS does (#1234 display/fold precedent).

Regressions synthesize the dialect spelling from the TempDir's own
drive (dialect/cygdrive/mnt operands list the operand drive, bare-drive
root lists the drive root, foreign-cwd negative, error spelling).
#1237)

namei probed every component of the raw operand text with
GetFileAttributesW, and Win32 resolves a leading '/e' against the
CURRENT drive: all drive-dialect forms ('/e/Data', '/cygdrive/e/Data',
'/mnt/e/Data') reported a broken chain ('f e (No such file or
directory)') for paths that exist on the named drive, from any cwd.

The operand now folds once through the shared make_api_path_operand
boundary and the walk runs on the folded native spelling, one
incremental prefix per step ('E:\' -> 'E:\probe-wb' -> ...), so every
component of a dialect chain resolves on the operand's drive. The
header line still prints the operand exactly as the user typed it,
and a genuinely missing component keeps the GNU broken-chain report.

Regressions synthesize the dialect spelling from the TempDir's own
drive (dialect/cygdrive/mnt chains resolve, bare-drive root is a
directory step, foreign-cwd negative, missing component still
reports, native form unchanged).
…1242)

look opened the dictionary file operand as raw text, and CreateFileW
resolves a leading '/e' against the CURRENT drive: '/e/words',
'/cygdrive/e/words' and '/mnt/e/words' all reported 'cannot open' for
a sorted word list that exists on the named drive, answering for the
cwd-drive shadow instead.

The operand now folds once through the shared normalize_api_operand
boundary at the open; the error message keeps quoting the operand
spelling as the user typed it (#1234 display/fold precedent).

Regressions synthesize the dialect spelling from the TempDir's own
drive (dialect/cygdrive/mnt dictionaries open and match, foreign-cwd
negative, error spelling, native form unchanged).
@caomengxuan666

Copy link
Copy Markdown
Member Author

独立代码评审:APPROVE

结论级:APPROVE(无 BLOCKER;3 条非阻塞备注见末尾。本评审未合并。)

评审基线:head 88b7411(4 提交)vs base 6e8ea19,自建 worktree 独立构建(build-cr1248, MSVC/Ninja Debug)+ 独立实跑全部验证点。

逐验证点

  1. 折叠完备性(核心)— 通过
    • tree:根操作数经 normalize_api_operand 一次折叠 → GetFullPathNameW 仅做相对补全 → collect_directory(abs_path) 全部下游使用折叠后的根,子级由 FindFirstFileW 自根枚举,无需再折叠,深层无泄漏路径。显式 tree . 折叠后仍为 ".",cwd 分支保留。
    • namei:入口 make_api_path_operand 折叠一次,native_walk_steps 在折叠后 native 串上取增量前缀。实跑覆盖 ..(d .. 正确逐段)、多斜杠 //(段折叠正确、探针有效)、junction reparse point 穿越后链继续解析、bare /e 单步 d E:\、bare E:、相对 .. 操作数——均正确。drive-relative E:abc 形态保留 Win32 语义。
    • look:唯一路径操作数(字典文件)在 read_lines 打开处折叠;查询词(key)未过折叠边界——正确,它是比较词不是路径。-f 是 ignore-case 开关,无第二个文件参数。
  2. 原文拼写审计 — 通过:tree cannot-access(console 与 -o 文件两条路)均用 spelling;namei header 逐字回显操作数、断链行只打印组件名(折叠仅重写盘前缀,组件文本逐字节不变,无折叠形泄漏);look cannot-open 用 cfg.file 原文。实跑验证:tree: cannot access '/e/probe-cr1248/absent1236'、look: cannot open '/e/probe-cr1248/lk/absent1242.txt' 均逐字保原文(ln 裸盘符根 /x 形态被 std::filesystem::absolute 拼接到 cwd——链接解析盘符随 cwd 漂移 #1234 display/fold 先例一致)。
  3. GNU 对照 — oracle 缺失,如实标注:MSYS(D:/Git/usr/bin/)无 tree/namei/look.exe(PATH 上仅 winuxcmd 自装副本,不构成独立 oracle);tree 本不在 GNU coreutils、namei 属 util-linux。三方格式比对未做,以下为行为合理性论证 + 落点见证:三方言 × 三命令全部落操作数盘(cwd 于 D:\ 见证);namei 断链保持 GNU「命名缺失组件 + errno 串」语义(f absent1237 (No such file or directory),格式为 WinuxCmd 先在风格,非本 PR 改动)。
  4. 矩阵实跑(cwd=D:\ 外盘 + cwd=E: 同盘对照,自建 E:\probe-cr1248 已自清):tree -L 2 /e/…、裸根 /e、/cygdrive/e/…、/mnt/e/… 全部落 E: 且 exit=0(修前形态为 cwd 根相对/断链);namei 三方言链逐段 d E:\ → … → f wbfile.txt;look 三方言输出匹配行(charlie/alpha/alpha);native 形态三命令不变。影子见证:C:\e、C:\d、D:\e、D:\probe-cr1248 全程 False(前后两次见证)。
  5. 回归实跑:16 项新回归(tree 5 + namei 6 + look 5)全过;TempDir 自身盘符合成设计在本机有效(TempDir=C:,foreign-cwd 实选 D: 真实跨盘执行,未跳过)。ctest 全量 3020 项:并行跑 14 失败(11×0xc0000409 + 3 Failed),与 tree/namei/look 零交集,14 项串行重跑 14/14 全过——并行负载 flake 实锤,本机净结果 3020/3020。
  6. 卫生:4 提交文件集 = 3 源文件 + 3 测试 + CHANGELOG,无夹带(namei 顺带删除的 else if (target.has_value()) `L `` 分支为不可达死代码,删除安全);未杀任何进程,无残留;CI 已核(x64/arm64/oracle/compare 全 SUCCESS,sync-i18n-catalog SKIPPED 合理——本 PR 未新增/改写 i18n key)。

非阻塞备注

感谢提交里顺带把 #1251(look 空尾行二分越界,非方言缺陷)单独开票而不是塞进本 PR。

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.

tree 裸盘符根 /x 形态 GetFullPathNameW 误解析——影子目录存在时静默列错(cwd 盘符漂移)

1 participant