Fix Windows temp-file cleanup failing on paths over MAX_PATH - #9452
alexreinking wants to merge 3 commits into
Conversation
compile_multitarget() names per-subtarget temp object files by concatenating the output prefix with the full, unelided subtarget suffix (every feature name), which can push the absolute path past the legacy Windows MAX_PATH limit (260 chars) once combined with a long temp directory path. _unlink()/RemoveDirectoryW() then silently fail for that one file, and TemporaryFileDir's destructor -- which doesn't check file_unlink()'s return value -- goes on to call RemoveDirectoryW() on a directory that still isn't actually empty, raising "error 145" (ERROR_DIR_NOT_EMPTY). Root-caused via a live repro: at the moment of failure, Sysinternals handle64.exe found no process anywhere on the system holding the file open (ruling out a lock/AV/indexer race), but the failing path was exactly 261 characters versus 245 for a sibling file that always deleted fine -- squarely the MAX_PATH boundary. Fixed by opting both file_unlink() and dir_rmdir() out of MAX_PATH via the well-known `\?\` long-path prefix (which requires an absolute, backslash-separated path, so the existing forward-slash paths are converted first). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
|
Isn't this going to hit other places we access the filesystem too? It just uses the new function for a single call. |
Likely yes, but this fixes the one issue I encountered and could reproduce locally. It would be worth an audit of the other |
|
Other potential issues in the same file are the calls to _access, _stat, and maybe ifstream, ofstream, CreateDirectoryW, and GetTempFileNameW Shouldn't we just wrap all the filename arguments to all file-system related calls inside WIN32 blocks? |
|
FWIW, prefixing a Windows path with
|
That's how this PR works |
|
Windows is ridiculous. We're dealing with limitations introduced 33 years ago... 😞 |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9452 +/- ##
==========================================
- Coverage 70.21% 70.05% -0.16%
==========================================
Files 261 261
Lines 79792 79940 +148
Branches 19451 19478 +27
==========================================
- Hits 56022 56005 -17
- Misses 17966 18065 +99
- Partials 5804 5870 +66 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Summary
Test plan