Skip to content

winx2: fix rm on device-name leaf dirs (#1297); regression pins for #1296/#1298 - #1392

Merged
caomengxuan666 merged 11 commits into
mainfrom
fix/winx2
Oct 26, 2026
Merged

caomengxuan666 merged 11 commits into
mainfrom
fix/winx2

Conversation

@caomengxuan666

@caomengxuan666 caomengxuan666 commented Oct 26, 2026 •

Copy link
Copy Markdown
Member

winx2 cluster: #1296/#1297/#1298 (mkdir/rm family).

Fixes #1297

#1297 — fixed here

rm -rf on a directory whose leaf is a DOS device name (e.g. NUL) silently exited 0 and left the directory in place. Root cause was not in rm: the shared boundary native_path::to_extended_path absolute-izes with GetFullPathNameW, which collapses a device-name leaf to the device itself (C:\…\pa\NUL → \\.\NUL), so every later probe reported INVALID and rm -f faked success. Fix (+22 in src/utils/native_path.cppm): operands whose leaf is a device name (and not the bare device) take the lexical absolute-ization path, same treatment as the #1283 dot/space spellings. All consumers (rm/ls/stat/cp/…) benefit; bare NUL device semantics are pinned unchanged.

#1296 / #1298 — not reproduced, regression pins only

On current main, mkdir on an existing directory already errors correctly (File exists, exit 1) and mkdir -p succeeds silently; the audit report predates the #1233/#1061 mkdir work. The mkdir/rm -v/--verbose shapes behave per GNU. This PR adds the regression pins as guards; both issues are being closed with the CI evidence.

Verification (real Windows CI, run 40305223127, this head)

…1296)

Regression pins for #1296 (from the #1283 audit, finding 3): mkdir on an
existing directory must fail with 'File exists' and exit 1, while
mkdir -p on an existing directory stays a silent success. Expectations
follow GNU mkdir. Not yet executed: the local same-source harness build
is still queued behind the machine-wide build slot, so these pins are
marked WIP; the PR's Windows CI run is the first execution and doubles
as the independent reproduction the issue asks for.
…uard (#1297)

Regression pins for #1297 (from the #1283 audit, finding 4): a real
on-disk directory named NUL (creatable only via the \\?\ spelling)
must actually be removed by rm -rf under its plain absolute spelling -
exit 0 alone is not success, the pin asserts the directory is gone via
an extended-path probe. A second pin keeps a bare NUL operand device-
only: nothing created or deleted, no hang. Not yet executed locally
(harness build still queued behind the machine-wide build slot); the
PR's Windows CI run is the first execution and doubles as the
independent reproduction the issue asks for.
…aths (#1298)

Regression pins for #1298 (from the #1283 audit, finding 5): -v must
not be silently ignored. rmdir -v was already pinned upstream
(rmdir_verbose_*), and mkdir -p -v was pinned too; the uncovered forms
were plain mkdir -v/--verbose and rm -v/--verbose (rm had no verbose
test at all). Expectations follow GNU wording as implemented by the
commands' existing message strings. Not yet executed locally (harness
build still queued behind the machine-wide build slot); the PR's
Windows CI run is the first execution and doubles as the independent
reproduction the issue asks for.
…the probe (#1297)

GetFileAttributesW on the extended spelling can report an existing directory whose name is a DOS device name (e.g. a literal NUL directory) as missing; rm -f then returned success without removing anything (confirmed on real Windows CI: exit 0, directory still present). When the attribute probe says missing and the operand leaf is a device name, confirm existence through a handle (CreateFileW + GetFileInformationByHandle) before treating the target as nonexistent. Also, when recursive enumeration reports no entries, attempt RemoveDirectoryW itself instead of concluding success. Bare device operands (whole-operand NUL etc.) are unchanged. No user-visible text changes; no i18n catalog impact.
Temporary, to be removed by the follow-up fix commit. The first fix attempt (14c9797) did not change the CI outcome, so pin down empirically which API step loses the directory on real Windows: GetFileAttributesW / CreateFileW / FindFirstFileW / RemoveDirectoryW / std::filesystem::remove_all on the extended spelling.
v1 result: every Win32 API handles the extended spelling correctly (GFAW(ext)=0x10 DIRECTORY, CreateFile/FindFirstFile/RemoveDirectoryW/remove_all all succeed), so the directory is lost inside rm flow, not in the OS probe. v2 observes rm itself.
v2 result: rm exits 0 with empty stdout/stderr and removes nothing for the NUL operand (both flag forms), while a control dir is removed normally. v3 uses -v and non-force runs to reveal what path rm believes it is processing.
v3 result: non-force rm reaches the INVALID-attributes branch with the correct original path string, while the same extended spelling stats fine (0x10) from the test process. Dump operand.normalized/extended/attr from inside rm.
…eaves onto the device (#1297)

Root cause, proven by in-process dumps on Windows CI: to_extended_path fed "C:\...\pa\NUL" to GetFullPathNameW, which collapses any path whose final component is a DOS device name onto the device itself and returns "\\.\NUL"; the extended operand became "\\?\UNC\.\NUL", every attribute probe reported INVALID, and rm -f silently succeeded without removing the real on-disk NUL directory (all other Win32 APIs handle the correct extended spelling fine: GetFileAttributesW=0x10, CreateFile/FindFirstFile/RemoveDirectoryW/remove_all all succeed). Route operands whose leaf is a device name (but which are not the bare device) through the lexical to_extended_path_preserving, the same treatment dot/space-final spellings already get (#1283). This also reverts the earlier rm-side probe fallbacks (14c9797) and the TEMP debug prints: the defect was never in rm, and with the boundary fixed the plain flow is correct.
The v1-v3 diagnostic tests served their purpose (root cause isolated to GetFullPathNameW device-leaf collapse in to_extended_path). The two #1297 regression pins stay.
@caomengxuan666 caomengxuan666 changed the title WIP: regression pins for #1296/#1297/#1298 (mkdir existing dir, NUL dir rm, -v output) Regression pins for #1296/#1298 (not reproducing) + fix #1297: device-named on-disk entries lost in to_extended_path Oct 26, 2026
@caomengxuan666 caomengxuan666 changed the title Regression pins for #1296/#1298 (not reproducing) + fix #1297: device-named on-disk entries lost in to_extended_path winx2: fix rm on device-name leaf dirs (#1297); regression pins for #1296/#1298 Oct 26, 2026
@caomengxuan666
caomengxuan666 marked this pull request as ready for review October 26, 2026 11:36
@caomengxuan666
caomengxuan666 merged commit 813b3b0 into main Oct 26, 2026
7 of 8 checks passed
@caomengxuan666
caomengxuan666 deleted the fix/winx2 branch October 30, 2026 01:42
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.

On-disk directory named NUL is undeletable: rm -rf resolves the operand to the device and reports false success

1 participant