Skip to content

fix(ls): keep drive-root separator when a dot collapse lands on the root - #1863

Merged
caomengxuan666 merged 1 commit into
mainfrom
lane-h/1862-ls-drive-root
Nov 23, 2026
Merged

caomengxuan666 merged 1 commit into
mainfrom
lane-h/1862-ls-drive-root

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #1862

UNVERIFIED-BY-CAPTAIN — lane H delivery, code only.

Defect

With the process cwd at a drive root (C:\, F:\), every relative ls operand failed:

C:\> ls
ls: cannot access '.': No such file or directory   (rc=2)
C:\> ls .
ls: cannot access '.': No such file or directory   (rc=2)

Non-root directories and the explicit C:\ spelling worked. Reproduced on master (3aaee819) with the rust2 driver under plain cmd (no niu): C:\ and F:\ roots, no-operand / . / .. all rc=2; control cwd C:\Users fine.

Root cause

One path, three steps (all in the ls operand boundary):

  1. fs_win::imp::api_path absolutizes . against the root cwd to \\?\C:\., then its trailing-dot cleanup strips the final \. and hands back the bare drive spelling \\?\C:.
  2. C: is the drive-RELATIVE spelling (that drive's current directory), and \\?\C: is rejected by the attribute probes — the lex_collapse header comment already records this.
  3. ls::lex_collapse preserved the root separator only when the input arrived carrying one (root_trailing: C:\ stays C:\). A collapse that lands on the root — C:\., C:\.., C:\dir\.., or the bare C: from step 1 — fell through and emitted C:.

Fix

Single mechanism, in lex_collapse (the one collapse every ls probe/enumerate path goes through): a collapse whose result is a bare drive component keeps the root separator, extending the existing root_trailing rule from "input carried the separator" to "result is the root". No operand special cases, no new path, no second normalization.

本 PR 删除了什么

Nothing deleted. The change widens one existing condition in lex_collapse (the separator-preservation rule) to cover the landing shape; it adds no mechanism, shim, or alternative path — the old behavior (emit bare C:) was not a feature any caller could rely on, since the probes reject that spelling outright.

Regression pins (rust2, cargo test -p winux-cmds, windows)

New ls::tests module in rust2/crates/winux-cmds/src/ls.rs:

  • lex_collapse_never_emits_a_bare_drive_root — \\?\C:, \\?\C:\., \\?\C:\.., \\?\C:\Users\.., \\?\F:\. all collapse to the rooted spelling; non-root collapses unchanged.
  • drive_root_cwd_lists_the_root — ls_cmd with Ctx cwd pinned to a real drive root: no operand, ., .., and the explicit root spelling all rc=0 with identical listings.
  • dot_operands_in_a_plain_directory_still_list — non-root control.

Fail-first (X299, master + pins only): 2 failed / control passed — left: "\\\\?\\C:" vs right: "\\\\?\\C:\\", and rc 2 cannot access '.' end-to-end. Fixed: full winux-cmds lib suite 1070 passed, 0 failed.

X299 live check (driver built from this tree, plain cmd, process cwd at root): C:\ no-operand / . / .. / C:\ / C:/ all rc=0, and the no-operand, . and C:\ outputs are byte-identical (30 lines); F:\ no-operand / . rc=0; C:\Users control unchanged.

Net lines

1 file changed: rust2/crates/winux-cmds/src/ls.rs +105 / −1 (net +104): the fix itself is +11 / −1 around lex_collapse; the rest is the new pin module. No user-visible text changes (no i18n impact). No workflow changes — the CMake 4.4.5 pin form is untouched.

…he root

Refs #1862

With the process cwd at a drive root, ls failed every relative
operand: cannot access '.' (rc 2). The operand boundary absolutizes
'.' against the root cwd as \?\C:\. and fs_win's trailing-dot
cleanup strips it to the bare drive spelling \?\C:, which the
attribute probes reject (C: is drive-relative). lex_collapse only
preserved the root separator when the input arrived with one, so
any '.'/'..' collapse landing exactly on a drive root emitted the
bare spelling.

Fix: in lex_collapse, a collapse landing on a bare drive component
keeps the root separator, the same rule root_trailing already
applied to separator-carrying inputs. One mechanism, no operand
special cases.

Pins (rust2, windows): lex_collapse never emits a bare drive root;
ls_cmd with Ctx cwd at a drive root lists it for no-operand, '.',
'..' and the explicit root spelling (identical output); plain-dir
control. Fail-first on master: 2 red / control green; fixed: full
winux-cmds suite 1070 passed on X299.
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