Skip to content

fix: canonicalize folds /cygdrive+/mnt like argv (#1246); look trailing-newline phantom entry (#1251); tree -o operand fold (#1254) - #1255

Merged
caomengxuan666 merged 3 commits into
mainfrom
fix/1246-1251-1254
Oct 19, 2026
Merged

caomengxuan666 merged 3 commits into
mainfrom
fix/1246-1251-1254

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Closes #1246. Closes #1251. Closes #1254.

Problem

Three follow-up defects, one per ticket:

Fix

Verification (PS/cmd native argv; #1230 — the local "Git Bash" is Niubash with MSYS argv pre-translation, so it was never used as an oracle)

Oracles: PowerShell Resolve-Path (Win32) + WSL GNU coreutils / util-linux look 2.39.3. Probe tree E:\probe-cr1246, cwds C:\Users\cmx and D:\repo, shell root unset and set — red on a fresh origin/main (8c19d14) build, green on this branch (cr-1246-matrix-base.txt vs cr-1246-matrix-pr.txt).

#1246 — realpath/readlink -f × {/cygdrive/e, /mnt/e} × {2 cwds × 2 shell-root states}:

probe (any cwd, root cleared unless noted) baseline 8c19d14 this branch
realpath /cygdrive/e/probe-cr1246/prog ENOENT E:\probe-cr1246\prog
realpath /mnt/e/probe-cr1246/prog ENOENT E:\probe-cr1246\prog
readlink -f /cygdrive/e/... / /mnt/e/... rc=1 E:\probe-cr1246\prog
realpath -m /cygdrive/e/.../nope <cwd>:\cygdrive\e\... (stranded); /cygdrive/e/... verbatim with root set E:\probe-cr1246\nope in all four states
stat / test -f / ls on the same spellings OK (argv boundary) OK — now agreeing with realpath/readlink
realpath -m /nodrive1246, /mntcc, /mnt/data1246 ordinary POSIX words unchanged (no over-folding)
/usr/bin, /etc, /dev/null shell-ns surface unchanged unchanged
oracle: WSL realpath /mnt/e/probe-cr1246/prog — E:\probe-cr1246\prog equivalent, three-way agreement

#1251 — three-form dictionaries vs util-linux look:

dictionary util-linux look 2.39.3 -f delt baseline this branch
…charlie\ndelta\n (trailing NL) delta (empty) delta
…charlie\ndelta (no trailing NL) delta delta delta
alpha\n\ncharlie\ndelta\n (middle empty) delta (empty) delta
look '' over middle-empty dict prints all incl. the empty line n/a (unit-tested; PS drops empty argv) identical
lone \n file, look '' one empty line two one

#1254 — tree -o /e/probe-cr1254/out.txt, both cwds:

witness baseline this branch
output file lands on E: (readable, GNU-shaped summary) no — open fails yes, both cwds
shadow <cwd-drive>:\e\probe-cr1254\out.txt absent (open failure), absent after absent

New regressions: realpath 2, readlink 2, stat 2 (incl. the NIT-2 stat /usr/bin shell-root pin), look 4, tree 2.

ctest

Full suite via scripts/build.py --skip-configure --run-tests (MSVC/Ninja/Debug) on the exact commit content: 3027/3035 passed; 8 failures are the disclosed #1245 flake family — TempDir create_directory races under suite load (mktemp_p_cygdrive_dir_outputs_cygdrive_form, ptx.ptx_auto_reference, sed.substitute_basic, sha512sum.sha512sum_check_without_valid_lines_reports_error, stat.stat_shell_root_usr_bin_resolves_through_shell_tree, ...). Every one passes in isolation, x3 consecutive runs; mktemp_p_cygdrive_dir_outputs_cygdrive_form also failed on the untouched 8c19d14 baseline during this session. None touch the changed surface (native_path resolver fold, look read loop, tree -o open).

Out of scope / unchanged

  • realpath on a zero-length dictionary-style operand and GNU look's "Invalid argument" on an empty file (GNU errors, we exit 0) — pre-existing, unrelated to the phantom-entry defect.
  • cygpath/mktemp raw-text prefix recognition — already handled at their own boundary.

…e argv boundary

canonicalize_path_w (realpath, readlink -f/-e/-m, stat -L) folded only the
single-letter MSYS drive form (#1231), so /cygdrive/e/... (#1145) and
/mnt/e/... (#1172) stranded on the cwd - or mapped under the shell root -
while stat/test -f/ls folded the same spelling at the argv boundary:
"test -f said yes, realpath said no" (#1246, #850 family, confirmed by the
#1245 review).

The prefix recognition moves into fold_posix_drive_prefix_w (byte-identical
conditions, single-sourced) and the resolver runs it before
fold_drive_dialect_w, mirroring normalize_api_operand_w's fold sequence;
normalize_api_operand_w calls the same helper so the two boundaries cannot
drift. A prefix operand is native-dialect input exactly like a drive-form
one: native spelling, never re-expressed as a shell-namespace path.

Also lands the #1245 CR nits: a regression pin for the intended stat side
effect (stat /usr/bin with a configured shell root resolves through the
shell tree like ls/readlink -f) and the CHANGELOG entry #1245 did not
carry. Caller-count wording per NIT-1 goes in the PR description (four
callers of canonicalize_path_w; winux_fifo_pipe_name_w's inputs are
pre-normalized, so the new fold is a no-op there).

Closes #1246.
…ary entry

The read loop emitted an empty line for the text after the last '\n', so a
standard trailing-newline dictionary ("...charlie\ndelta\n") carried a ""
entry at the END of its sorted line array. "" sorts before every key, but
the binary search's midpoint can land on the phantom and push lower_bound
past the last real word: `look -f delt` printed nothing (#1251).

The final newline at EOF now contributes no entry, matching util-linux
look 2.39.3 (WSL oracle): `look -f delt` on "...delta\n" prints delta,
`look ''` over a trailing-newline dictionary prints every real word and no
trailing empty line, and a lone "\n" file is exactly one empty entry.
Empty lines in the middle of the dictionary keep working as real entries.

Closes #1251.
tree folded its read-side root operand through normalize_api_operand since
#1236, but the -o file operand went to ofstream as raw text. Win32 resolves
a leading "/e" against the CURRENT drive, so from a foreign cwd
`tree -o /e/probe/out.txt` failed to open (or would have written a shadow
"<cwd-drive>:\e\probe\out.txt") instead of writing on the named drive -
the write-side blind spot of the #1230 sweep (#1248 CR n2).

The output operand folds once through the same boundary as the root; the
open-failure message keeps quoting the spelling as typed (#1234 split).

Closes #1254.
@caomengxuan666

Copy link
Copy Markdown
Member Author

Independent code review — verdict: APPROVE

Reviewed independently from my own worktrees — PR head 6d347be (three commits over 8c19d14, each Closes exactly its own ticket) and a detached baseline at origin/main (a6e4990, which has advanced past this branch with #1250/#1253/v1.1.17). git merge --no-commit origin/main in the review worktree is clean: only CHANGELOG/PROJECT_VERSION/date/ldd/shred auto-merge from main, zero conflict with this PR's nine files. One environment note: the dev preset's BUILD_FFI=ON cannot configure a clean checkout (src/ffi does not exist at either commit; it only exists untracked in the main checkout) — both review builds used -DBUILD_FFI=OFF, matching the main checkout's working build-dev cache. Pre-existing quirk, unrelated to this PR.

Verified (all re-executed; fixture E:\probe-cr1255 created and removed by the review; foreign cwd C:\Windows; shell-root cleared of all four env vars or explicitly set)

  1. Byte-identical extraction: fold_posix_drive_prefix_w vs the old inline normalize_api_operand_w conditions, compared side by side on both revisions — cygdrive branch (size ≥ 8+3, separator[0], case-insensitive "cygdrive" loop, drive_pos 10, separator at [9], terminator size==11 || separator[11]) and mnt branch (size ≥ 3+3, case-sensitive "mnt", drive_pos 5, separator at [4], terminator size==6 || separator[6]), same result "/" + substr(drive_pos), same order cygdrive → mnt → fold_drive_dialect_w. The helper's early return after the first match is equivalent to the old sequential inline (a folded result can never match the next prefix: /e/… has no mnt at [1..3]). fold_drive_dialect_w body moved verbatim. No drift.
  2. Resolver sequence mirrors the argv boundary: canonicalize_path_w now strips, runs the prefix fold, then the drive fold, and only otherwise maps through the shell tree — on the same (possibly prefix-folded) operand; a folded prefix operand is never re-expressed as a shell-namespace spelling, with or without a root. Caller closure re-checked: readlink.cpp:152, realpath.cpp:149, stat.cpp:1098 (so -e/-m/stat -L are covered) plus the internal winux_fifo_pipe_name_w whose inputs arrive pre-normalized via make_api_path_operand — the fix(native-path): fold the POSIX drive dialect in canonicalize_path_w (#1231) #1245 NIT-1 four-caller wording in the PR description is accurate.
  3. Matrix baseline vs PR, all flips red→green exactly as claimed: realpath -m /cygdrive/e/... BASE <cwd>:\cygdrive\e\... stranded walk → PR E:\...; same for /mnt/e/...; realpath default mode /mnt/e/... BASE ENOENT → PR native; readlink -f both prefixes BASE rc=1 silent → PR native. stat on the same spellings is green on both builds (argv boundary since 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) — the "test -f said yes, realpath said no" disagreement is gone, witnessed on one operand. Drive-form control (/e/...) green on both — no regression of realpath/readlink -f 裸盘符根 /x 形态静默拼接 cwd——canonicalize_path_w 共享入口缺盘符折叠 #1231.
  4. Shell-root two states: with __RUBASH_SHELL_ROOT set, prefix operands resolve to the native spelling on the PR (BASE captured the spelling into the shell namespace / echoed it verbatim); /usr/bin still resolves through the shell tree on both builds (stat /usr/bin → directory, rc 0) — the fix(native-path): fold the POSIX drive dialect in canonicalize_path_w (#1231) #1245 NIT-2 pin (stat_shell_root_usr_bin_resolves_through_shell_tree) locks the intended side effect, and the CHANGELOG lines fix(native-path): fold the POSIX drive dialect in canonicalize_path_w (#1231) #1245 lacked are carried here.
  5. Fold-order combination probes (PR vs BASE): /cygdrive/m → M:\ on PR (cygdrive→/m→drive root; BASE verbatim — bug shape), /mnt/m → M:\ both, /cygdrive/mnt/x and /mnt/cygdrive/e/x verbatim on both (no over-folding: after the mnt fold the result's first segment is cygdrive, not a drive), /cygdrive/e/mnt/y → E:\mnt\y PR only, /e/mnt/e/x → E:\mnt\e\x both. Every PR answer equals what the argv boundary answers for the same spelling.
  6. Negatives byte-identical 11/11 (stdout+stderr+rc, BASE vs PR): /nodrive/x, /mntcc/x, bare /mnt, /mnt/data, /cygdrive2/x, /cygdriv/x, /123/x, stat /dev/null, stat /mntcc/x, readlink -f /nodrive/x, /usr/bin without a root. No over-folding, no drift.
  7. look 尾部换行产生空尾行使二分 lower_bound 越过最后真实词条(非方言缺陷,Wave2-B 顺带发现) #1251 vs a real oracle: I ran util-linux look 2.39.3 under WSL myself. All seven shapes byte-equal to the PR: trailing-NL dict -f delt → delta (BASE: empty — the phantom-entry bug reproduced exactly as ticketed); trailing-NL dict look '' → four real words, no trailing empty line (BASE: extra \n); middle-empty dict -f delt → delta; middle-empty dict look '' → all four lines including the empty one, byte-equal; no-trailing-NL dict identical on BASE and PR (both correct before); lone \n file → exactly ONE empty entry (BASE: two). The disclosed zero-length-file divergence (GNU rc=1 vs here rc=0 with empty output) reproduces as described and is untouched.
  8. tree -o 输出操作数未过方言折叠(写侧盲区)——#1248 CR n2 #1254 landing witness: tree -o /e/..., -o /cygdrive/e/..., -o /mnt/e/... from the foreign cwd — BASE rc=1 cannot open output file on all three; PR rc=0 with the file landing on the operand's drive, GNU-shaped summary bytes, and zero shadow (C:\e\..., C:\Windows\e\..., C:\cygdrive\..., C:\mnt\... all absent after every run). The open-failure message quotes the typed spelling byte-identically on BASE and PR (display/fold split holds).
  9. Tests: exactly 12 new cases (look 4 / readlink 2 / realpath 2 / stat 2 / tree 2), 12/12 green on the PR build and absent from the baseline build (0 name matches at a6e4990). The realpath tests cover both shell-root states; the tree test includes the shadow negative.
  10. ctest: full PR suite solo → 3035 run, 23 failures, all the known random 0xc0000409/assertion flake family — all 23 pass serially, none recur, and the one flake on the changed surface (look.look_lone_newline_file_is_single_empty_entry) passes 3× consecutive look-suite runs. Running both suites concurrently inflated failures to 143 (PR) / 137 (BASE) symmetric — proof of load sensitivity, not a PR property. Baseline solo → 3037 run, 8 failures, a disjoint random set. Consistent with the disclosed flake family; the PR's numbers are credible.
  11. Hitchhiking scan clean: the branch is exactly 9 files over 8c19d14; f46d2cd = native_path + 3 resolver test files + CHANGELOG (Closes #1246), 706a205 = look.cpp + look tests + CHANGELOG (Closes #1251), 6d347be = tree.cpp + tree tests + CHANGELOG (Closes #1254). No format churn, no unrelated edits, CHANGELOG wording matches the code.

Non-blocking notes

  1. Flake family breadth under load: this host's fail-fast flake family yields more members when suites run under CPU pressure (23 solo here, 143/137 with two suites at once) than the 8 disclosed. Every member passes in isolation and none sits on the changed surface — no action needed for this PR, but the family is worth a dedicated quarantine ticket someday.
  2. tree -o inherits the boundary's trailing-separator semantics (ENOTDIR keep-separator for non-directories) since it now goes through normalize_api_operand. That is the [gap] trailing '/' on a regular file is silently stripped: readers accept it, tee/dd/cp/mv write through it (data loss), some errors report ENOENT or exit 0 #1052 contract applied symmetrically to the write side — correct, just noting the write operand's behavior is now boundary-consistent rather than raw-ofstream.
  3. Zero-length dictionary: GNU look errors (rc=1), WinuxCmd returns 0 with no output — pre-existing, accurately disclosed in the PR description as untouched. Fine.

Review hygiene: no processes were killed (none needed); both review worktrees and the E:\probe-cr1255 fixture tree were removed after the review; the main checkout was only read.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant