Repository navigation
fix(mkdir,ln): fold POSIX drive-dialect operands before any write (#1233, #1234) - #1243
Merged
Merged
Conversation
) mkdir handed the raw operand ('/e/Data', '/cygdrive/e/Data', '/mnt/e/Data') to CreateDirectoryW / create_directories, and Win32 resolves a leading '/e' against the CURRENT drive: from a C: cwd 'mkdir -p /e/Data' really created a shadow C:\e\Data tree - the only audited misparse that writes to the wrong place (#1230 sweep). An existing E:\Data also reported ENOENT instead of 'File exists', and -m/-v answered for the shadow path. The operand now folds once through the shared normalize_api_operand boundary on entry to create_directory; the -m and existence helpers fold likewise. GNU-style messages keep printing what the user typed, like MSYS. Regressions synthesize the dialect spelling from the TempDir's own drive (land-on-operand-drive, cwd-on-other-drive shadow negatives, bare-drive root no-op, verbose operand form) and pass on any host.
ln resolved '/e/...' sources and targets against the cwd drive: std::filesystem::absolute spliced a rooted no-drive operand onto the cwd (msvc semantics), and GetFileAttributesW / FindFirstFileW / CreateHardLinkW / CreateSymbolicLinkW all answered for '<cwd>:\e\...'. From a C: cwd the hard-link source probe failed with "failed to access", -t DIR rejected a real directory, and a privileged 'ln -s /e/Data /e/Data/link' wrote the link beside the cwd instead of on E:. Sources and targets now fold once per job (and in the -t / 2-operand / implicit-target-directory probes) through the shared normalize_api_operand boundary before any Win32 call; -r computes the relative form from the folded pair. Create-stage error text quotes the operand spelling as typed (display strings ride alongside the API forms), matching MSYS. Regressions synthesize the dialect spelling from the TempDir's own drive (hard-link landing + cwd-on-other-drive shadow negative, directory-target join, -t directory, symlink landing, message-spelling pin) and pass on any host; the symlink case skips on hosts without the privilege.
Member
Author
Independent review: APPROVE-WITH-NITSReviewer: independent CR agent for #1243. All checks below were re-executed from scratch (own worktree at d640dbb, own MSVC builds of both base e991ba8 and PR head), not taken from the PR description. Verified points
Non-blocking notes
BLOCKERS: none. Merge as-is or with nit (a) addressed at the author's discretion. |
…nit) The force-removal helper received the folded target and embedded it in 'failed to remove ...', so 'ln -fT /e/x /e/nonempty' printed the 'E:\...' API form where every other message prints what the user typed - a violation of the verbatim-message invariant this branch declares. remove_existing now takes a display string alongside the folded API path, same plumbing as create_hardlink/create_symlink. Regression: ln_fT_drive_dialect_remove_failure_message_keeps_operand_ spelling forces the deterministic non-empty-directory refusal through dialect operands and pins the raw spelling. Live witness (PS native argv, cwd=C:\): 'ln -fT /e/Data/src-w2.txt /e/Data/nonempty-w2' -> "failed to remove '/e/Data/nonempty-w2'", no shadow, zero residue after cleanup.
Member
Author
|
NIT addressed on this branch (head
|
This was referenced Oct 19, 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.
Closes #1233. Closes #1234. Both found by the #1230 all-command sweep.
What
mkdirandlnaccepted POSIX drive-dialect operands (/e/Data,/cygdrive/e/Data,/mnt/e/Data) and handed the raw text to Win32. A leading/eresolves against the CURRENT drive, so every resolution drifted with cwd:C:cwd,mkdir -p /e/Datareally created a shadowC:\e\Datatree - the only audited misparse that writes to the wrong place. An existingE:\Dataalso reported ENOENT instead ofFile exists, and-m/-vanswered for the shadow path.std::filesystem::absolutespliced rooted no-drive operands onto the cwd (MSVC semantics);GetFileAttributesW/FindFirstFileW/CreateHardLinkW/CreateSymbolicLinkWall answered for<cwd>:\e\...- hard-link source probe failed withfailed to access,-t DIRrejected a real directory, and a privilegedln -s /e/Data /e/Data/linkwrote beside the cwd instead of on E:.How
Per the ticket direction: operand entry folds once through the shared
normalize_api_operandboundary - no error-report-layer patches.mkdir.cpp:create_directoryfolds the operand on entry (creation,-precursion,-m, existence/verbose helpers consume the folded form); GNU-style messages keep printing what the user typed.ln.cpp: sources and targets fold once per job and in the-t/ 2-operand / implicit-target-directory directory-detection probes;-rcomputes the relative form from the folded pair; create-stage error text quotes the operand spelling as typed (display strings ride alongside the API forms - found during probe round 1, where the folded form leaked intofailed to create hard link 'E:\Data\hard-w2'while MSYS prints the operand spelling).Verification
Unit: full ctest 2993/2993 passed (local, Debug). New regressions synthesize the dialect spelling from the TempDir's own drive, so they hold on any host: land-on-operand-drive, cwd-on-other-drive shadow negatives, bare-drive-root
-pno-op (themkdir -p /e->C:\ecase), verbose operand form,-t/dir-target join, symlink landing (privilege-skip honored), message-spelling pin.Live write-side probes (PowerShell native argv only; MSYS oracle =
D:/Git/usr/bin/{mkdir,ln}.exe; landing witnessed byTest-Pathon E: and shadow absence on C:/D:):mkdir -p /e/Data/probe-w2C:\eD:\emkdir /e/Data/probe-w2(after -p)File exists, exit 1, no shadowFile exists, exit 1mkdir /e/Data(existing, ticket repro)File exists(was ENOENT), no shadowFile existsln -s /e/Data /e/Data/link-w2Operation not permitted); noC:\e\Data\link-w2ln /e/Data/probe-w2 /e/Data/hard-w2(dir)hard link not allowed for directoryln /e/Data/probe-w2/marker.txt /e/Data/hard-w2(positive control)C:\e\Data\hard-w2Notes: the symlink landing row is privilege-bound on this host for both our build and the oracle (identical error text = parity); the positive landing witness for the same per-job fold machinery is the hard-link row, plus the unit test
ln.ln_symlink_drive_dialect_lands_on_operand_driveon privileged hosts. The dir-hardlink message text (Permission deniedvs GNU'shard link not allowed for directory) is pre-existing Win32 error mapping, out of scope here.Cleanup: every probe product deleted after each round; post-cleanup
Test-Path=FalseforE:\Data,E:\Data\probe-w2,E:\Data\link-w2,E:\Data\hard-w2,C:\e,C:\d,C:\e\Data,D:\e,D:\e\Data- zero residue (probe baseline also started clean).Provenance
Branch continues the rescued WIP of the previous agent (worktree
winuxcmd-wt-1233, diff preserved atworktree-rescue-20261019b/winuxcmd-wt-1233.diff). Inherited as-is after line-by-line review (covers all write/probe call sites; matches both tickets' stated direction), with two corrections added on top: the create-stage message-plumbing fix above, and its regression pin.