Repository navigation
Preserve explicit drive letters in GetFullPathName - #156
Conversation
| std::string hostInput = hasDriveRoot ? input.substr(2) : input; | ||
| std::filesystem::path hostPath = files::pathFromWindows(hostInput.c_str()); |
There was a problem hiding this comment.
std::filesystem::path hostPath = files::pathFromWindows(input.c_str()); still works here, right?
There was a problem hiding this comment.
Only for C:/Z: — pathFromWindows only strips those two prefixes. For D:\foo it'd return the relative path D:/foo, which absolute() then joins onto the cwd. Stripping any X:\ first handles every drive letter (covered by the D:/d: cases in test_fullpath.c). hostInput still goes through pathFromWindows, so case-insensitive resolution etc. is unchanged.
Maybe we could make pathFromWindows strip any drive letter instead. That would change how every file API maps other drives (for example, CreateFile("D:\x") would open /x). It's broader than this fix.
There was a problem hiding this comment.
Aha, I see. This feels like a very subtle workaround for a kinda broken pathFromWindows, and a sketchy one at that: it assumes that you can drop the drive letter and expect behavior to be unchanged. Which I think is true right now, because we map z: and c: to the same thing, but if we changed that it would do case insensitive file system lookups in the wrong place.
Suggestion: preserve only c:.
There was a problem hiding this comment.
alternative suggestions:
- change pathFromWindows to handle other drive letters, returning e.g.
/mnt/d/... - assert that only c: or z: appear
There was a problem hiding this comment.
or just change pathFromWindows to resolve all drive letters the same way as c: I guess
There was a problem hiding this comment.
Otherwise we could make GetFullPathName not touch the filesystem at all. The docs (https://learn.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-getfullpathnamea) say
- "merges the name of the current drive and directory with a specified file name",
- "does not verify that the resulting path and file name are valid, or that they see an existing file", and
- "does not convert the specified file name" (that's what GetLongPathName is for).
We currently do convert it. Even for C:, C:\USR\BIN..\LIB comes back as C:\usr\lib because pathFromWindows matches it against /usr. Wine returns C:\USR\LIB.
I would suggest we make computeFullPath purely lexical on the Windows path: resolve against the Windows cwd, collapse ./.., strip trailing dots, and never call pathFromWindows. That avoids the drive-mapping question.
what do you think?
There was a problem hiding this comment.
Sure, sounds good to me
There was a problem hiding this comment.
I pushed a new commit as suggested. It has a set of tests that pass on wibo and wine. Let me know what you think.
|
|
||
| std::string windowsPath = files::pathToWindows(absPath); | ||
| if (hasDriveRoot) { | ||
| // The host path has no drive; retain the caller's instead of the default Z:. |
There was a problem hiding this comment.
yes I was not sure about that one. I removed it.
Resolve against the Windows cwd, collapse . and .., strip trailing dots and spaces, and never map through pathFromWindows, so arbitrary drive letters and component case are preserved as Windows does.
|
@simonlindholm thank you for your review and guidance! |
In Wibo 1.2.0, passing an already absolute Windows path changes its drive:
Input: C:\Code\game\main\foo.pdb
Expected: C:\Code\game\main\foo.pdb
Actual: Z:\Code\game\main\foo.pdb
Both ANSI and Unicode variants are affected, and the target file does not need to exist. The same reproduction preserves C: under Wine 11.19.
The cause is the Windows → host → Windows conversion in computeFullPath(): pathFromWindows() strips the drive prefix, and pathToWindows() always adds Z: for absolute host paths. This loses the caller’s original drive.
This affects MSVC6 LINK: /PDB:C:\Code\game\main\foo.pdb embeds a Z: path in the output DLL’s NB10 CodeView record.