Skip to content

fix(fs): collapse '..' at the api_path boundary; directory-open probe decides by attribute (#1872) - #1873

Merged
caomengxuan666 merged 2 commits into
mainfrom
fix/1872-dotdot-operands
Nov 25, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
fix/1872-dotdot-operands

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #1872
Refs #1869 (承接:本单是 #1871 关单矩阵暴露的 .. 残面,#1871 的盘根修复不动)

UNVERIFIED-BY-CAPTAIN — code-only 交付,队长复核后合入。

机制定位(devin-windows 实机探针,std/FFI 直测)

两个面、一个主根:

  1. fs-meta 家族(stat/touch)+ fmt 家族的路由探针:imp::api_path 只折叠 .、明文留下 ..,于是 verbatim 串带着点段抵达属性层——GetFileAttributesW("\\\\?\\C:\\l4probe\\..")、"..\\l4probe" 中段形、"\\\\?\\C:\\." 均为 error 123 (ERROR_INVALID_FILENAME),折叠后的拼写正常应答。即:任何含 .. 组件的操作数对 stat/touch 必红(Invalid argument),且 fmt/fold/paste 在 open 失败后用来判定目录类的 file_meta 探针同路被污染、目录类永不触发,只剩原始 Permission denied 漏出。
  2. fmt 家族的显式根形:File::open("C:\\") 本身失败为 error 3 (ERROR_PATH_NOT_FOUND)(普通目录是 error 5 ACCESS_DENIED)——三个 applet 的目录路由都以 kind == PermissionDenied 为门,根形永远进不去,报成 No such file or directory。

find/pathchk/du/ls/rm/tee 全绿的原因也随之清楚:它们或走平路径(Win32 自行规范化)、或自带词法折叠(ls 的 lex_collapse,其注释里正写着为 api_path 不折叠 .. 打的补丁)。

修复(共享层单点 ×2)

  • imp::api_path:新增 collapse_dot_segments,在既有 . 折叠所在的同一操作数边界上对 ./.. 一并做词法折叠——.. 弹前一组件、钳制于根(盘符/UNC server+share 不可弹)、落盘根恢复分隔符(fs_win api_path mangles drive-root paths (C:\. -> \?\C:), shared by stat/rm/touch/du/find and more #1869 规则)、尾随分隔符保留;无点段的拼写逐字节直通。原地删除旧的 . 专用字符串手术。
  • fsutil::failed_open_is_directory(新共享谓词):目录类翻译不再看 open 的 error kind,只看属性探针。fmt/fold/paste 三处复制的 PermissionDenied && file_meta… 表达式收敛为对该谓词的一次调用(同根多点,已按简报口径在此说明)。

ls 的 lex_collapse 就此对 api_path 输出成为幂等空转(其另一输入 abs_probe_path 仍需要它),本 PR 不动 ls。

fail-first 留痕(devin-windows,gnu 工具链跑 crate 测试)

  • 钉提交 85247df:9/9 红,红签名与实机报告逐字吻合(fmt dir/.. → "cannot open … Permission denied"、fmt C:\ → "No such file or directory"、api_path 三组串钉、stat/touch/fold/paste applet 钉)。
  • 修复提交 45709dd:9/9 绿;全量 lib 测试 1083 过、1 红 df::tests::type_filters——已在 pristine 161d6d66 同机 A/B 复现,为 devin-windows 主机环境存量红,与本 PR 无关。

实机验收(devin-windows,本分支 driver 构建跑 #1872 形状集)

  • stat 9/9 rc=0、touch 9/9 rc=0(.@根、C:\.、C:\、..@l4probe、..@ctrl、C:\l4probe\..、C:\l4probe\..\l4probe、ctrl\..\ctrl、..\ctrl);touch 经 ctrl\..\newfile1872 在正确父目录建文件、同形删除 rc=0。
  • fmt 5/5 "read error"、fold/paste 5/5 "Is a directory"(含 C:\ 与全部 .. 形)——与 CTRL 错误类逐项对齐,fs_win api_path mangles drive-root paths (C:\. -> \?\C:), shared by stat/rm/touch/du/find and more #1869 的 . 面无回退。
  • 回归绿面:find/pathchk/ls/du 的 .. 形 rc=0;rm 对 C:\l4probe\.. 报 Is a directory;tee 目录操作数 Permission denied(与其 CTRL 类一致,未变)。

删除节 / 净行账

  • 删除:api_path 内 . 专用手术(两处 while 循环)——被 collapse_dot_segments 单一机制取代;fmt/fold/paste 三份 PermissionDenied && file_meta 探针表达式——收敛为 fsutil 单一谓词。无断言删改、无测试删除。
  • 净行:全 PR +270 / −45(钉提交 +158/−0;修复提交 +116/−49,其中生产代码为 fs_win 折叠 + fsutil 谓词 + 三 applet 改线)。
  • I18N:无用户可见文本新增/变更(错误消息原文不动,仅路由条件变化),无目录同步需求。

残注

  • UNC 拼写的 floor(server+share 钳制)在 collapse_dot_segments 内按 ls::lex_collapse 同规则防御性实现,但未立静态钉:UNC 操作数先经 winux-core 的 shell-tree 映射,静态期望串不可靠;实机矩阵为盘形全覆盖。

…e/touch)

Fail-first pins for the '..' component face split from #1869:
api_path string pins (trailing/mid/root-climb/guard shapes) and
applet-layer pins for stat, touch, and the fmt/fold/paste directory
error class. No production code changes.
… decides by attribute (#1872)

imp::api_path now collapses '.' and '..' components lexically
(collapse_dot_segments) where it previously collapsed '.' only:
a verbatim path carrying a dot segment is rejected by the
attribute layer with ERROR_INVALID_FILENAME (probed on a real
host), so every '..' operand failed stat/touch with Invalid
argument and broke the fmt/fold/paste is_dir routing probe.

The fmt/fold/paste directory translation no longer gates on the
open's error kind (a drive root fails ERROR_PATH_NOT_FOUND, an
ordinary directory ERROR_ACCESS_DENIED); the three copies of the
probe expression collapse into fsutil::failed_open_is_directory.
@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN-VERIFY — merging.

Reviewed head 45709dd. Mechanism evidence is FFI-level and decisive: verbatim \\?\ paths carrying .. return ERROR_INVALID_FILENAME (123) from GetFileAttributesW in every position, while the lexically collapsed forms succeed — api_path collapsed . but passed .. through, and ls only looked immune because it carries its own collapse (its comment says exactly why). The fix collapses dot segments in api_path itself (component stack, clamped at the drive/UNC floor, root separator restored) and converges the fmt family's three copied directory-probes into one shared predicate keyed on the target's attributes rather than the open error kind (the drive-root open reports error 3, never the PermissionDenied the old gate waited for).

Fail-first on a real Windows host: 9/9 red with signatures matching the field report verbatim, 9/9 green after; the full acceptance matrix re-ran green on the host (stat/touch 9/9, fmt/fold/paste error classes correct including C:\), no regression on the #1869 . face or the green families. PR CI 28 pass / 4 skipping / 0 fail. The one unrelated red the lane saw locally (df::tests::type_filters) was A/B-reproduced on pristine — a host-environment leftover, not this change.

Closes the .. face split out of #1869.

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