Skip to content

fix(mkdir): anchor drive-absolute operands at the drive root in the -p walk (#1870) - #1875

Merged
caomengxuan666 merged 2 commits into
mainfrom
fix/1870-mkdir-anchor
Nov 25, 2026
Merged

caomengxuan666 merged 2 commits into
mainfrom
fix/1870-mkdir-anchor

Conversation

@caomengxuan666

Copy link
Copy Markdown
Member

Refs #1870. Also carries the #1101 acceptance the captain promised on that issue (see Verification). UNVERIFIED-BY-CAPTAIN — lane code + host evidence only; not self-merged.

Defect (as filed, reproduced on v1.2.3 and on the pre-fix branch head)

mkdir -p mishandled drive-absolute operands in both spellings:

  • D1 — D:/a/b/c with the cwd on D:: rc=0, the target is never created, and the tree silently lands under the caller's cwd.
  • D2 — D:\a\b\c: -p creates no parents at all; the leaf create fails ENOENT unless every parent already exists.

Mechanism, in create_parents (rust2/crates/winux-cmds/src/mkdir.rs): every non-folded walk started at the cwd and split only on /. For D1 the walk re-joined the D: component onto the cwd — the join drops the root and Win32 resolves the result against the per-drive cwd. For D2 the whole backslash spelling arrived as a single component, so the walk made exactly one create attempt on the full path.

Fix (one point, in the walk)

A drive-absolute fs_name (X: + separator) now takes the anchored decomposition the folded forms already used — root = the drive root, components split on both separators via the Path parent chain — whether or not a fold claimed the operand. The fold chain itself is untouched: prepare_operand still returns these spellings unchanged, and they were never the fold's to claim.

Display prefixes are now sliced from the operand text at its component ends instead of re-joined, so -v lines and diagnostics name each created directory exactly as spelled (a backslash operand keeps its backslashes: mkdir: created directory 'D:\wt\a\b').

Unchanged on purpose: bare D: and drive-relative D:name keep their per-drive-cwd reading; the folded (/e/Data), POSIX-rooted, and relative walks behave as before (guards pin this).

What this PR deletes

  • The cwd-anchored treatment of drive-absolute operands in the -p walk (the D1/D2 mechanism itself).
  • The re-join display construction (shown_comps[..=end].join("/") plus the absolute_shown special case) — replaced by operand-sliced prefixes.
  • A no-op let _ = &mut acc; leftover in the relative branch.

Net-line accounting

One file (rust2/crates/winux-cmds/src/mkdir.rs), +213/−35 total: pins +146/−0, production +67/−35. No new messages, no user-visible text changes (diagnostics reuse the existing reporting paths; only the path spelling inside them is now operand-faithful) — no I18N catalog impact.

C++ twin review (per the lane brief)

Reviewed, no such face on the C++ side, no C++ change in this PR:

Boundary with #1874 (captain asked this lane to evaluate bundling)

Evaluated: separate mechanisms, not bundled — full evidence in the lane report. In one line: the anchoring lives in one applet's walk decomposition, while #1874's missing carrier encoding lives in the shared fold_carrier_colons (both operand chains, every applet) whose final-component scope is a pinned contract with its live C++ twin. Confirmed empirically on this branch's build: after this fix, ls x:y/z and mkdir -p q:w/c (colon in a non-final component) still fail while the U+F03A spellings work — that face survives this PR by design and belongs to #1874's own lane.

Verification (devin-windows, Windows Server 2022)

Vehicle note: the host has no VS/MSVC linker, so tests and the acceptance matrix ran on the 1.99.1-x86_64-pc-windows-gnu toolchain through winuxcmd-driver — the same winux_cmds::dispatch the shipped exe calls (the #1873 precedent). Judgment surface is the library logic; the MSVC shipping build is for CI.

  • Fail-first (pins commit on pre-fix code): 3 red with the filed signatures — D1 pin: rc 0 but target missing (the shadow tree was found under the test process's cwd and removed); D2 pins: cannot create directory '...': No such file or directory, rc 1. Guards green pre-fix, as designed.
  • After the fix: mkdir module 12/12 green; full winux-cmds lib 1088 passed with the single failure df::tests::type_filters A/B-reproduced on pristine 3940c00 (host-environment leftover, unrelated); winux-core lib 34/34. cargo fmt --check clean for the touched file.
  • Host matrix (PowerShell, driver as the exe): 22/22 — D1a/D1b/D2a/D2c/P1 shapes (target created at the drive root, cwd clean), -v backslash prefixes, relative-path regression, no--p still rc=1, plus the [bug] applets fail on literal-colon operands: canon layer does not carrier-encode operand path components #1874 separation spot-checks above.
  • ln -s: "./"-prefixed relative targets stored verbatim are unresolvable by native Windows consumers (+ false-negative ENOENT on relative targets) #1101 acceptance (niu from the W2 tree, bundled mkdir.exe temporarily replaced by a forwarder to this branch's driver, restored afterwards): 12/12 — the reporter's three named shapes stay clean (rc 0, targets built, no stray D+U+F03A in the cwd), and the two explicit-exe shapes that used to collide with D2 (/d/... from C:) and D1 (D:/... from D:) now create at the target with the cwd untouched.

Fail-first pins for the drive-absolute -p face: D1 same-drive slash
form (tree must land at the absolute target, not under the cwd),
D2 backslash form (parents must be created, -v prefixes keep the
operand spelling), cross-drive D1b/D2c guards (self-skipping without
a second writable drive), the POSIX drive-form fold guard, and the
no-parents single-create guard. No production code changes.
…p walk (#1870)

create_parents started every non-folded walk at the cwd and split
only on '/': a same-drive 'D:/a/b/c' re-joined its 'D:' component
onto the cwd, the join dropped the root, and Win32 resolved the
result against the per-drive cwd — the tree landed under the
caller's cwd, the target was never created, rc 0 (D1). The
backslash spelling 'D:\a\b\c' arrived as one component, so -p
created no parents and the leaf create failed ENOENT (D2).

A drive-absolute fs_name now takes the anchored decomposition the
folded forms already used (drive root + both-separator split),
whether or not a fold claimed it. Display prefixes are sliced from
the operand text at its component ends instead of re-joined, so
-v and diagnostics name each created directory exactly as spelled
(backslash operands keep their backslashes). Bare 'D:' and
drive-relative 'D:name' keep their per-drive-cwd reading; the
folded, POSIX-rooted and relative walks are unchanged.
@caomengxuan666

Copy link
Copy Markdown
Member Author

CAPTAIN-VERIFY — merging.

Reviewed head c420b46. The mechanism read is exact: prepare_operand never mangled the drive-absolute spellings — the non-collapsed walk in create_parents did, by starting from the cwd and splitting only on /, which re-anchored the D: component onto the cwd (D1: same-drive silent drop with rc=0; the cross-drive shape only looked right by accident) and treated a backslash path as a single component (D2: one create_dir, parents never made). The fix routes drive-absolute operands through the same anchored decomposition as the collapsed forms, and the display prefix is sliced from the operand as written, so -v output and diagnostics keep the caller's spelling byte for byte. Bare D:, D:name, POSIX and relative walks are untouched and pin-guarded. The C++ side was audited in the PR: mkdir.cpp has been a registration shell since #1488 and native_path.cppm passes these forms through correctly — no twin defect.

Fail-first: 3 reds with signatures matching the field report verbatim (including the shadow tree photographed under the test process's cwd), guards green before and after. Host matrix 22/22 on a real Windows host; PR CI 28 pass / 4 skipping / 0 fail. The local df::tests::type_filters red was A/B-reproduced on pristine — host leftover, not this change.

The #1874 separation argument in the PR is accepted: different layer, a live C++ twin with its own pin baseline, and a different regression surface — it proceeds as its own PR (#1876), not folded into this one.

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