GnuWin32版mkdir疑似存在路径创建Bug?
Hey there, I can confirm this is definitely a known bug in the GnuWin32 port of mkdir (part of CoreUtils) version 5.3.0. The root issue is how the tool parses absolute paths when the target drive matches your current working directory's drive—it incorrectly interprets the drive-qualified path as a relative path, hence the directories getting created under your current sandbox folder instead of the root of drive C.
Let's recap your test cases to make this clear:
Test Case 1 (Cross-Drive: C → Q)
This works as intended. The tool correctly identifies Q:/scratch/foo/bar as an absolute path on a separate drive, so it creates the directory hierarchy exactly where specified. Here's the output you saw:
C:\sandbox>"C:\Program Files (x86)\GnuWin32\bin\mkdir.EXE" --verbose -p Q:/scratch/foo/bar C:\Program Files (x86)\GnuWin32\bin\mkdir.EXE: created directory `Q:/scratch' C:\Program Files (x86)\GnuWin32\bin\mkdir.EXE: created directory `Q:/scratch/foo' C:\Program Files (x86)\GnuWin32\bin\mkdir.EXE: created directory `Q:/scratch/foo/bar'
Test Case 2 (Same-Drive: C → C)
This is where the bug shows up. The output pretends it's creating C:/scratch/foo/bar, but in reality, it dumps the directories into your current working directory (C:/sandbox/scratch/foo/bar). The output looks correct, but the actual filesystem change is wrong:
C:\sandbox>"C:\Program Files (x86)\GnuWin32\bin\mkdir.EXE" --verbose -p C:/scratch/foo/bar C:\Program Files (x86)\GnuWin32\bin\mkdir.EXE: created directory `C:/scratch' C:\Program Files (x86)\GnuWin32\bin\mkdir.EXE: created directory `C:/scratch/foo' C:\Program Files (x86)\GnuWin32\bin\mkdir.EXE: created directory `C:/scratch/foo/bar'
Updated Win32 CoreUtils Ports
Unfortunately, GnuWin32 has been essentially abandoned for years—CoreUtils 5.3.0 from 2007 is the last official release. But there are actively maintained alternatives that fix this and other Windows path issues:
- MSYS2: Provides up-to-date builds of GNU CoreUtils (current versions are in the 9.x range). Their
mkdirproperly handles Windows absolute paths, including same-drive scenarios. It's easy to install and offers standalone binaries if you don't want the full environment. - Cygwin: Another well-maintained port that includes fully functional CoreUtils with proper Windows path support. It's more heavyweight than MSYS2 but great if you need a complete Unix-like environment on Windows.
If you need a quick fix, switching to either of these ports will resolve the mkdir path issue immediately.
内容的提问来源于stack exchange,提问作者DaveC

