Repository navigation
feat(native-path): resolve /mnt/X WSL interop drive operands (closes #1172) - #1227
Conversation
…1172) normalize_api_operand_w folds /mnt/X to the MSYS /X spelling before the drive branch, so a single drive-letter arm keeps owning every POSIX drive form (#1145 structure). WSL mounts the Windows drives under /mnt and that spelling reached argv verbatim whenever a tool was invoked directly - PowerShell, cmd, a scheduler, an agent - or built its own child argv (xargs / find -exec chains, the rubash PR#600 tool-side lane); rubash's argv funnel already pre-translates the form for every child (#444, #592), so the two layers now agree on the same shape without double-translation (rubash hands the applet C:\... and the native arms stay inert). Shape matches rubash's windows_mnt_drive_argument byte-for-byte so the two repos never drift: a lowercase mnt literal (unlike the case-insensitive cygdrive name - deliberate, two-repo parity over local symmetry), a drive letter of either case folded to uppercase, exactly /mnt/X or /mnt/X/... Boundaries (ticket (a)-(e)): - /mnt and /mnt/ (the WSL root) never fold: verbatim standalone, and the niubash#346 shell-tree mount semantics (<root>/mnt) under a shell root. - Non-drive children (/mnt/data, /mnt/cfoo, /mnt/123) stay verbatim. - /mnt/cygdrive/d cannot fold twice (load-bearing negative test). - Zero new or modified verbatim exemptions: /cygdrive/*, /dev/*, bare /, /X... switches, relative words all untouched. Every tool on the shared operand boundary (ls, du, sed, cp, ...) picks the form up at once via make_api_path_operand_w (#1178 routed du/sed); canonicalize (realpath/readlink) deliberately stays out - its GNU semantics do not fold /d/x either. Tests (ls_unit_test.cpp, the #1145 style; standalone cases clear all four shell-root variables, drive letters derived from TempDir): - ls_mnt_drive_dialect_resolves: lower/upper drive x file/-d/bare root, operand echoed as typed. - ls_mnt_non_drive_forms_stay_verbatim: /mnt, /mnt/, /mnt/data, /mnt/cfoo, /mnt/123, /mnt/cygdrive/<drive>/<existing> double-fold guard; rc=2 with the operand echoed verbatim. - ls_mnt_forms_keep_shell_root_semantics: /mnt/c still resolves with a shell root configured (fold result = the old shell-ns arm result) and ls -1 /mnt still lists <root>/mnt (no #346 regression). Full ctest: baseline origin/main (b4f7834) 2975 cases / post-change 2978 cases (3 new); failure sets identical modulo the machine-state locale_hint pair (installed zh-CN catalog on this machine) and the mktemp cygdrive case that only fails under an inherited __RUBASH_SHELL_ROOT - the same Niubash injection that produced the rubash#568 probe artifact.
独立评审(PR #1227 / #1172 /mnt 折叠臂)结论:REQUEST-CHANGES — 1 个可证实的边界实现缺陷(一行修复),其余设计决策、双层无冲突、测试与改动面全部实证通过。 F1(需修改):折叠臂漏掉
|
| 操作数 | rc | 实际效果 |
|---|---|---|
ls /mntcc |
0 | 列出 C:\ 根(= ls /c) |
ls /mntcd |
0 | 列出 D:\ 根(= ls /d,输出逐行一致) |
ls /mntcc/Windows |
0 | 列出 C:\Windows |
ls /mntab/c |
2 | 词法上已折成 B:\c(本机无 B: 才表现为 ENOENT) |
- 违反本 PR 自述契约:注释(
native_path.cppm:379-384)与 CHANGELOG:18-20 都承诺"exactly/mnt/Xor/mnt/X/..."、与 rubashwindows_mnt_drive_argument"byte-for-byte"。rubash 侧(src/executor/path.rs:1857-1863)用starts_with("/mnt/")要求字节 4 是/,本臂没有 —— 逐字一致的主张对这一类输入不成立,两层真实漂移。 - 与紧邻其上的 cygdrive 臂不对称:后者显式有
is_separator(normalized[1 + k_cygdrive_name.size()])(:366 附近)。设计记录 (c) 自己写的"[5] 为字母且 [6] 为分隔符或串尾"也隐含 [4] 已是/。 - 修复(一行,与 cygdrive 臂对齐):条件中加
is_separator(normalized[k_mnt_name.size() + 1]) &&。is_separator接受\\,故既有 backslash 形(\mnt\c)不受影响(已实测\mnt\c路径当前可折,修复后同样可折)。 - 建议补承重负例(现有负例全是
[4]=='/'形,抓不到这一类,已变异验证):在ls_mnt_non_drive_forms_stay_verbatim的 forms 表加机器无关的L"/mnt" + drive + drive + text.substr(2)(如/mntcc/Users/...指向 TempDir 本身):修复前 rc=0(折到真实盘路径),修复后 rc=2 verbatim。
F2(nit,随 F1 一并改):"byte-for-byte" 表述在修复前为假
CHANGELOG.md:19 与 native_path.cppm:380。F1 修复后该表述成立,保留即可;仅提醒不要只改代码忘改文案(当前两处都在)。
已实证通过的部分(均亲手复现,非转述)
- 设计决策核实:用 cmd 清变量 + 本机 Niubash 安装的原 1.1.14(修复前)二进制复现完整矩阵——
ls /mnt/c/Windows清四变量 rc=2(缺口);注入__RUBASH_SHELL_ROOTrc=0([candidate] vdir: bug(vdir): when using -R with a large nested file it leads to a no human readable err (uutils#12827) #346 门控臂);niu -c顶层 rc=0(引擎翻完传C:\...,安装树 ls 是修复前版本,能通只能是引擎侧翻译)。[noise-panic] #seq -f %aaborts (out-of-memory) on a large-magnitude exponent that GNU formats fine (uutils#13222) #568"直打已通"的假象归因(env 注入→shell-ns 臂)成立。 - 双层无冲突:
ls.exe 'C:\Windows'(已是 Win32 形)原样放行、缺路径报错回显原操作数——native 各臂均需[0]为分隔符,不触发。find/xargs 端到端:echo /mnt/c/Windows | xargs ls -drc=0;find /mnt/cygdrive/cc/Windows -maxdepth 0rc=1(verbatim)。 - 边界 (a)-(e)(F1 之外全部成立):(a)
/MNT、/Mntverbatim(小写字面量契约与 rubashstarts_with一致;GNU/cygwin 对/mnt无既定行为,对齐 rubash 是自洽选择);(b)/mnt、/mnt/standalone verbatim,配 shell root 时<root>/mnt挂载语义保持(手测 marker.txt 用例通过);(c)/mnt/data|cfoo|123verbatim;(d)/mnt/cygdrive/d无双折;(e) 豁免表零新增、零修改(diff 仅一个折叠臂)。 - 变异测试(改源→重建→跑 3 个新测试,用后已还原):删臂 →
ls.ls_mnt_drive_dialect_resolves转红(正例锁臂);仅换序 → 全绿(前缀互斥,换序行为中性,与设计记录一致);仅放宽[6]条件 → 本机 ctest 仍绿但手动探测/mnt/data已被折到D:\data(存在性撞运气);放宽+换序 →ls.ls_mnt_non_drive_forms_stay_verbatim转红(双折护栏确为承重负例,与测试注释一致)。shell-root 用例(1416)在删臂下仍绿——它护的是 [candidate] vdir: bug(vdir): when using -R with a large nested file it leads to a no human readable err (uutils#12827) #346 不回归,不是新臂,合理。 - 全量 ctest:2978 项(= 2975 基线 + 3),2976 过,失败恰为 2 个预存
locale_hint(winuxcmd_unit_test.cpp:681/682/699,i18n 目录环境态,与本 PR 改动面无关)。 - 改动面:严格 3 文件(CHANGELOG/native_path.cppm/ls_unit_test.cpp),纯新增 192 行;新增行零超 80 列、零尾随空白(本机无 clang-format 可执行文件,按 .clang-format ColumnLimit=80 及风格逐行核对,格式与相邻 cygdrive 臂一致);
L"/mnt/"拼接全部走operator+(const wchar_t*, std::wstring),无指针算术残留;CHANGELOG[Unreleased]/### Added/- **native path**:与仓库既有惯例一致。 - 许可证:实现为原创小匹配器(与仓内 Per-command gaps resolving verbatim POSIX argv: cp/mv/ls(file,-d) fail on /d/... drive paths while cat/mktemp/ls(dir) resolve them (blocks niubash#124 Option B) #1145 cygdrive 臂同构同风格),无 WSL/cygwin 代码搬运标识(无 lxss/wslpath/cygwin_conv 等符号),LICENSE 不变;canonicalize(realpath/readlink)走
canonicalize_path_w,有意不在面内,现状对称。
建议
修 F1(一行条件 + 一个负例 + CHANGELOG/注释核对口径)后即可合入。其余全部放行。
…1172) CR finding on #1227: the fold arm checked the mnt name, the drive letter and the tail boundary but not the separator between "mnt" and the letter, so /mntcc lexically folded to /c and named C:\ - "ls /mntcc" listed the drive root and /mntab/c folded to B:\c. rubash's windows_mnt_drive_argument gets this constraint from starts_with("/mnt/") and the sibling cygdrive arm from its is_separator check; the arm now requires is_separator(normalized[k_mnt_name.size() + 1]) and the byte-for-byte claim against rubash's matcher is true again (the comment now spells out the separator and the /mntcc trap; the CHANGELOG shape sentence was already "exactly /mnt/X or /mnt/X/..." and needed no change). Load-bearing negatives added to ls_mnt_non_drive_forms_stay_verbatim (both land on existing paths when the check is missing, so verbatim-missing is the only distinguishable outcome): /mnt<drive><drive> (the CR repro - lists the drive root when broken) and /mnt<drive><drive>/<existing tmp file> (exercises the tail-separator arm). Verified red on the pre-fix build - exactly the 2 new forms failed with rc=0 - and green after the one-line condition fix; ls_mnt suite 3/3; full ctest re-run 2978 cases, failure set unchanged (only the machine-state locale_hint pair).
F1 已修复(42d8841),三件套齐① 条件修复( ② 负例加测试(
红→绿取证:先在未修构建物上加测试跑 → 恰好这 2 个新形态红( 直打复核(PowerShell 原生 argv,standalone):
③ 文案核对:
回归面:全量 ctest 2978 例复跑,失败集与修复前完全一致(仅 2 个机器状态 locale_hint——本机已装 zh-CN catalog),零新增零消失。clang-format:native_path.cppm 的 4 处 dry-run 报点全为预存上游行(clang-format-22 与已提交风格的历史分歧,不属本 PR 触碰面);测试文件除我的新数组重排外零变化。 请 CR 复核。 |
复核轮:APPROVE(42d8841)F1 三件套全部独立复核通过,无新增 finding。逐条取证: ① 条件修复: ② 新负例(自跑 + 变异):修复构建物(清四个 shell-root 变量直打)—— ③ 正例回归 + 全量: ④ 改动面: #1172 缺口修复完整、边界与两层契约对齐、测试承重。LGTM。 |
fix(native-path): resolve /mnt/X WSL interop drive operands (closes #1172)
现象与需求面(实测定位)
normalize_api_operand_w只有 /cygdrive 折叠(#1145)+ 单字母/X/盘符臂 + niubash#346 的 shell-root 门控 shell-ns 臂。standalone(无 shell root 环境变量)时/mnt/c/...落空:实测矩阵(本机 Win10 19045,PowerShell 原生 argv,本 PR 构建物;修复前 → 修复后):
winuxcmd ls /mnt/c/Windows/System32/attrib.exewinuxcmd du -s /mnt/c/Windowswinuxcmd sed -n 1p /mnt/c/Windows/win.iniwinuxcmd touch /mnt/c/<tmp>__RUBASH_SHELL_ROOT在场)winuxcmd ls /mnt/c/...niu -c 'ls /mnt/c/...'(niu 1.4.0 = rubash e785c3c8,含 #592)两个关键实证:
__RUBASH_SHELL_ROOT/NIU_ROOT,走的是 [candidate] vdir: bug(vdir): when using -R with a large nested file it leads to a no human readable err (uutils#12827) #346 shell-ns 门控臂;清掉变量即复现缺口。本次实测坐实,rubash#568 方向 A(维持 [wording] Split enters endless loop (uutils#14118) #444)的裁决前提无误。niu -c实测 ✅):feature: native 层解析 /mnt/X 形态(WSL 互操作路径;rubash#568 裁决实证全系无支持) #1172 的真实需求面 = 不经 rubash 的直接调用 + rubash PR#600"已知边界"显式归工具侧的 xargs/find -exec自构造子 argv 链。归属裁决:native 单层落地,rubash 侧不动(两层各管各的面)
与 rubash#592(PR#600)的层面对照表
external_command_for_named_program:一切外部命令、一切执行上下文(for/子壳/函数/管道/-c/script)find -exec自构造子 argv 链(PR#600 显式划归工具侧车道)/mnt/X处理windows_mnt_drive_argument恒翻译(#444 起,非豁免)normalize_api_operand_w新折叠臂 →/X/→ 既有盘符臂 →X:\mnt字面量;盘符[A-Za-z];精确/mnt/X或/mnt/X/...([6]分隔符或串尾)/mnt、/mnt/data/cygdrive/X/C:\...原生形,native 各臂不触发、原样放行结论:与
/X/盘符形的既有双层格局(#1145 工具侧 + #592 引擎侧)完全同构;rubash 侧 #444 carve-out 维持现状,撤除预翻译仍按票面"先 probe 后迁移"另议。设计决策((a)-(e),票上已记录:#1172#issuecomment-6249391156)
mnt小写字面量(WSL 只发小写;从 rubash 契约区分大小写——与 /cygdrive 折叠的名字大小写不敏感刻意不同,两仓一致优先);盘符双 case 接受、折叠为大写(与既有单字母臂、cygdrive 折叠、rubashto_ascii_uppercase三方一致)。/mnt、/mnt/(WSL 根):永不折算。standalone → verbatim(<cwd盘>:\mnt语义,现状不变);shell root 配置时维持 [candidate] vdir: bug(vdir): when using -R with a large nested file it leads to a no human readable err (uutils#12827) #346 的<root>/mnt挂载语义(shell-ns 分支不动,新增测试锁定)。/mnt/X或/mnt/X/...([5]字母且[6]分隔符或串尾)折算。/mnt/data、/mnt/cfoo、/mnt/123→ 原样;/mnt/c/Users→C:\Users✅。/mnt折叠(新)→ 单字母盘符臂(唯一所有者,延续 Per-command gaps resolving verbatim POSIX argv: cp/mv/ls(file,-d) fail on /d/... drive paths while cat/mktemp/ls(dir) resolve them (blocks niubash#124 Option B) #1145 "single drive-letter branch owns every POSIX drive form")。/mnt/cygdrive/d不折且无双折(承重负例测试:错误双折会命中存在路径而转绿);/cygdrive/mnt/c两前缀都不匹配 → verbatim;两前缀互斥,无同时匹配。/cygdrive/*、/dev/*(resolve_pseudo_device_w独立)、裸/、开关形/X...、相对词——全部原状;新折叠触发面 = 之前 standalone verbatim 的/mnt/[A-Za-z](/...)严格子集。修法(一个点,全工具受益)
src/utils/native_path.cppmnormalize_api_operand_w(cygdrive 折叠与单字母盘符臂之间):新增/mnt→ MSYS 拼写折叠臂,34 行,结构照抄 cygdrive 折叠(Per-command gaps resolving verbatim POSIX argv: cp/mv/ls(file,-d) fail on /d/... drive paths while cat/mktemp/ls(dir) resolve them (blocks niubash#124 Option B) #1145)。make_api_path_operand_w/normalize_api_operand),ls/grep/find/cp 等早已在内——单点改动即票面"winuxcmd 自己的工具直接收到 /mnt/X"全系生效。canonicalize(realpath/readlink)有意不在面内(其 GNU 语义对/d/x也不折,现状对称,不扩翻译面)。tests/unit/ls/ls_unit_test.cpp(Per-command gaps resolving verbatim POSIX argv: cp/mv/ls(file,-d) fail on /d/... drive paths while cat/mktemp/ls(dir) resolve them (blocks niubash#124 Option B) #1145 既有风格,Pipeline 黑盒;standalone 用例显式清四个 shell-root 变量,机器无关——TempDir 动态取盘符):ls_mnt_drive_dialect_resolves:/mnt/<盘>/...小写/大写盘符 × 文件/-d目录/裸盘根/mnt/<盘>→ rc=0 且操作数原样回显;ls_mnt_non_drive_forms_stay_verbatim:/mnt、/mnt/、/mnt/data、/mnt/cfoo、/mnt/123、双折护栏/mnt/cygdrive/<盘>/<存在的 tmp 文件>→ rc=2 且 stderr 原样回显操作数;ls_mnt_forms_keep_shell_root_semantics:配置 shell root 后/mnt/c仍通(折叠臂结果 = 原 shell-ns 臂结果),且ls -1 /mnt仍列<root>/mnt挂载内容([candidate] vdir: bug(vdir): when using -R with a large nested file it leads to a no human readable err (uutils#12827) #346 不回归)。CHANGELOG.md:[Unreleased] Added 条目。I18N:本变更零用户新增文案(错误信息沿用既有键),无 catalog 影响。验证
ctest -R ls_mnt→100% tests passed, 0 tests failed out of 3。99% tests passed, 3 tests failed out of 2975;本 PR 后99% tests passed, 2 tests failed out of 2978(2975 + 本 PR 3 个新测试)。基线 3 个失败逐一溯源均与本 PR 无关且非代码回归:mktemp.mktemp_p_cygdrive_dir_outputs_cygdrive_form:本开发 shell 继承 Niubash 注入的__RUBASH_SHELL_ROOT所致的会话污染;env -u __RUBASH_SHELL_ROOT -u NIU_ROOT -u WINUXSH_ROOT -u RUBASH_ROOT下单独复跑即绿(同一注入也正是 [noise-panic] #seq -f %aaborts (out-of-memory) on a large-magnitude exponent that GNU formats fine (uutils#13222) #568 复测假象的来源)。winuxcmd.locale_hint_*× 2:本机已安装 zh-CN catalog(Niubash 安装树),"catalog missing → 建议 wpm install" 的前提不成立,机器状态类预存失败,clean 基线上同样失败。/mnt/c全通(矩阵见上);边界/mnt、/mnt/data仍 verbatim。红线自查
-u/-w转换器有自己的契约(mktemp/cygpath 认裸前缀文本),不动,翻译面未扩大。/mnt/X形状规则一致,无新增豁免、无新增漂移。closes #1172