fix(fs): prevent ENOENT on subst drive root paths like "M:\\" on Windows#58989
fix(fs): prevent ENOENT on subst drive root paths like "M:\\" on Windows#58989mag123c wants to merge 2 commits intonodejs:mainfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #58989 +/- ##
==========================================
- Coverage 90.14% 90.05% -0.09%
==========================================
Files 630 645 +15
Lines 186784 189130 +2346
Branches 36653 37089 +436
==========================================
+ Hits 168377 170327 +1950
- Misses 11205 11511 +306
- Partials 7202 7292 +90
🚀 New features to boost your workflow:
|
1474ed1 to
fcaee03
Compare
|
I've force-pushed a fix (e.g. lint issue resolved). |
When using fs.readdir() or fs.readdirSync() on subst drive root paths such as M:\, Node.js was incorrectly adding a second backslash, resulting in M:\\, which caused ENOENT errors on Windows. This patch adds a safeguard to avoid appending a backslash if the path already represents a drive root, including both standard (e.g. C:\) and namespaced (e.g. \\?\C:\) formats. Fixes: nodejs#58970
fcaee03 to
c97462b
Compare
|
I apologize - the format-cpp check failed again. I've pushed another fix to address the formatting issue. This appears to be an unrelated test, as:
|
Failed to start CI⚠ No approving reviews found ✘ Refusing to run CI on potentially unsafe PRhttps://github.com/nodejs/node/actions/runs/16441290676 |
StefanStojanovic
left a comment
There was a problem hiding this comment.
Approving to enable starting the CI. Still not approved to land AFAIC.
|
Hello @mag123c what's the status on this? Are there still some changes to be implemented before reviewing? |
a3d9423 to
83e2c46
Compare
|
@StefanStojanovic
Ready for review. |
|
@StefanStojanovic The upstream fix uses a simpler approach: |
This PR fixes an issue where
fs.readdirSync('M:\\')and related calls would fail with anENOENTerror on Windows when using subst drive roots.Previously, Node.js added a trailing backslash (
\) even when the input path was already a drive root (e.g.,M:\or\\?\M:\), resulting in invalid paths likeM:\\\. This patch introduces a check to detect standard and namespaced drive root formats and avoid appending an extra slash in those cases.The fix is Windows-specific and scoped only to the logic within
fs.readdir.Changes
src/node_file.ccto detect and skip appending\for drive root pathstest/parallel/test-fs-readdir-windows-subst.jssubst-like paths with and without trailing slashesENOENTerror is thrown for valid drive rootsContext
Fixes: #58970