Repository navigation
fix(native-path): fold the POSIX drive dialect in canonicalize_path_w (#1231) - #1245
Conversation
…#1231) canonicalize_path_w - the shared resolver behind realpath, readlink -f/-e/-m and stat -L - walked '/e/Data' operands as if they had no root name, so the component walk started at the current directory and every dialect operand stranded on the cwd drive ('realpath /e' from a foreign cwd literally resolved '<cwd>\e'; PS probe with native argv, #1230 discipline). Single-source the recognition rule: extract the drive fold that normalize_api_operand_w (#1145) applied inline into fold_drive_dialect_w, and consult it in canonicalize_path_w before the component walk and before the shell-tree mapping (shell_tree_map_w already declines drive forms). The rule stays 'first segment is exactly one drive letter': /cygdrive/X (#1145) and /mnt/X (#1172) keep folding through their own branches, multi-letter first segments (/usr, /etc, /mntcc) are never drives, and the verbatim exemption surface gains nothing. stat.cpp routes its operand through make_api_path_operand_w like every other consumer, so the lstat probe, -L resolution, the symlink display line and -f report the named file instead of a cwd-stranded ENOENT. New regressions: readlink/realpath/stat dialect operands resolve from a foreign cwd, bare '/x' is the drive root, '-m' keeps the native spelling, multi-letter first segments stay ordinary POSIX words, and stat lstat/-L report dialect symlinks.
3da7218 to
05abdc5
Compare
|
CI run 1: x64 failed only Fixed in 05abdc5: assertions now check the GNU shape — operand echoed, target�s size/regular-file metadata, and no lstat |
Independent code review — verdict: APPROVE-WITH-NITSReviewed independently from a fresh worktree at 05abdc5, with a merge-preview against origin/main (3c5d9ad, includes #1243): merge is clean (ort, no conflicts; #1243 touches mkdir/ln/CHANGELOG + their tests, zero file overlap with this PR's stat.cpp / native_path.cppm / readlink+realpath+stat tests). Verified (all re-executed, PS native argv per #1230; my own "Git Bash" channel was discarded as an oracle once it proved to be Niubash with MSYS argv pre-translation — exactly the fake-green trap this PR calls out)
Nits (non-blocking)
|
Closes #1231.
Problem
canonicalize_path_w(native_path.cppm) — the shared component-wise resolver behindrealpath,readlink -f/-e/-mandstat -L— walked POSIX drive-dialect operands (/e/Data) as if they had no root name: the component walk started at the current directory, so the operand stranded on the cwd drive. From any cwd,realpath /eliterally resolved<cwd>\e; with a foreign cwd the whole surface reported ENOENT for files that exist.The argv operand boundary (
normalize_api_operand_w) has folded the drive form since #1145, but these three resolvers receive the raw operand text and never pass through that boundary.Fix (shared layer, one place)
normalize_api_operand_wintofold_drive_dialect_wso the rule stays single-sourced: first segment exactly one drive letter (/x,/x/...→X:\,X:\...)./cygdrive/X(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) and/mnt/X(feature: native 层解析 /mnt/X 形态(WSL 互操作路径;rubash#568 裁决实证全系无支持) #1172) keep folding through their own branches before this rule is consulted; multi-letter first segments (/usr,/etc,/tmp,/mntcc) are never drives — zero new verbatim exemptions.canonicalize_path_wfolds the dialect before the component walk and before the shell-tree mapping (shell_tree_map_walready declines drive forms). A drive-form operand resolves to the native spelling and is never re-expressed as a shell-namespace path, with or without a shell root configured.stat.cpproutes its operand through the existing shared boundary (make_api_path_operand_w) like every other consumer, so the lstat probe,-Lresolution and the symlink display line stop probing the raw spelling.canonicalize_path_whas exactly three callers (realpath, readlink, stat), so the blast radius is the broken surface itself.Verification (PS/cmd native argv; MSYS-channel probes fake-green, #1230)
Probe tree
E:\probe-w1(Data dir, file, junction), cwdsC:\Users\cmxandD:\repo, red on a freshe991ba8build, green on this branch. Oracles: PowerShellResolve-Path(Win32) + WSL GNU coreutils (/mnt/e/...) three-way agreement; the local "Git Bash" is Niubash and pre-translates dialect argv, so it was used only as an in-shell convention reference, never as a probe channel.realpath /e/probe-w1/DataE:\probe-w1\Datareadlink -f /e/probe-w1/DataE:\probe-w1\Datastat -L /e/probe-w1/Datastat /e/probe-w1/Datarealpath /e<cwd>\e(wrong)E:\stat -f /e/probe-w1/Datarealpath /e/probe-w1/jlink(reparse)Health layer, same matrix, no degradation on either build:
ls/du/cat/cp/cygpath/mktempwith/e/...,/cygdrive/e/...and/mnt/e/...operands all unchanged; verbatim shell-namespace surface intact (ls /usr/binincl. theX.exeleaf rule,realpath /etcechoes the mount name,cat /dev/nullempty with exit 0, and/e/...still resolves natively with a shell root configured).New regressions: readlink (2), realpath (4, incl. bare
/x= drive root,-mnative spelling,/nodrivestays a POSIX word) and stat (4, incl. lstat/-Ldialect behavior; symlink cases skip on non-elevated hosts).ctest
Full suite via
scripts/build.py --run-tests(MSVC/Ninja/Debug): 2992/2992 green on the final state of this branch. Two earlier runs showedb2sum_check_reports_unreadable_listed_files,head_count_suffixes,head_missing_file_reports_gnu_shaped_open_errorandmktemp_p_cygdrive_dir_outputs_cygdrive_formfailing non-deterministically; all four pass in isolation (repeated x5) and the same flake signature appears on the untouchede991ba8baseline build (its suite run failedmktemp_p_cygdrive_dir_outputs_cygdrive_formtoo), so none are introduced here.Known adjacent gaps (out of scope, unchanged by this PR)
realpath /cygdrive/e/...and/mnt/e/...:canonicalize_path_wstill only folds the single-letter form; those prefixes fold at the argv boundary (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/feature: native 层解析 /mnt/X 形态(WSL 互操作路径;rubash#568 裁决实证全系无支持) #1172), which these resolvers bypass. Identical behavior before and after this change; worth a follow-up if the resolvers should accept the prefix spellings too.