Repository navigation
winx2: fix rm on device-name leaf dirs (#1297); regression pins for #1296/#1298 - #1392
Merged
Merged
Conversation
…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
marked this pull request as ready for review
October 26, 2026 11:36
This was referenced Oct 26, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
winx2 cluster: #1296/#1297/#1298 (mkdir/rm family).
Fixes #1297
#1297 — fixed here
rm -rfon 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 boundarynative_path::to_extended_pathabsolute-izes withGetFullPathNameW, which collapses a device-name leaf to the device itself (C:\…\pa\NUL→\\.\NUL), so every later probe reported INVALID andrm -ffaked success. Fix (+22 insrc/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; bareNULdevice semantics are pinned unchanged.#1296 / #1298 — not reproduced, regression pins only
On current main,
mkdiron an existing directory already errors correctly (File exists, exit 1) andmkdir -psucceeds silently; the audit report predates the #1233/#1061 mkdir work. Themkdir/rm -v/--verboseshapes 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)