Skip to content

Commit 21fc818

Browse files
bcoecodebytere
authored andcommitted
fs: set path when mkdir recursive called on file
PR-URL: #31607 Fixes: #28015 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Richard Lau <[email protected]>
1 parent 7c3cc94 commit 21fc818

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

src/node_file.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,6 +1234,7 @@ int MKDirpSync(uv_loop_t* loop,
12341234
}
12351235
break;
12361236
case UV_EACCES:
1237+
case UV_ENOTDIR:
12371238
case UV_EPERM: {
12381239
return err;
12391240
}
@@ -1309,6 +1310,7 @@ int MKDirpAsync(uv_loop_t* loop,
13091310
break;
13101311
}
13111312
case UV_EACCES:
1313+
case UV_ENOTDIR:
13121314
case UV_EPERM: {
13131315
req_wrap->continuation_data()->Done(err);
13141316
break;
@@ -1351,7 +1353,6 @@ int MKDirpAsync(uv_loop_t* loop,
13511353
}
13521354
// verify that the path pointed to is actually a directory.
13531355
if (err == 0 && !S_ISDIR(req->statbuf.st_mode)) err = UV_EEXIST;
1354-
uv_fs_req_cleanup(req);
13551356
req_wrap->continuation_data()->Done(err);
13561357
}});
13571358
if (err < 0) req_wrap->continuation_data()->Done(err);

test/parallel/test-fs-mkdir.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ function nextdir() {
148148
message: /ENOTDIR: .*mkdir/,
149149
name: 'Error',
150150
syscall: 'mkdir',
151+
path: pathname // See: https://github.com/nodejs/node/issues/28015
151152
}
152153
);
153154
}
@@ -187,6 +188,11 @@ function nextdir() {
187188
assert.strictEqual(err.code, 'ENOTDIR');
188189
assert.strictEqual(err.syscall, 'mkdir');
189190
assert.strictEqual(fs.existsSync(pathname), false);
191+
// See: https://github.com/nodejs/node/issues/28015
192+
// The path field varies slightly in Windows errors, vs., other platforms
193+
// see: https://github.com/libuv/libuv/issues/2661, for this reason we
194+
// use startsWith() rather than comparing to the full "pathname".
195+
assert(err.path.startsWith(filename));
190196
}));
191197
}
192198

0 commit comments

Comments
 (0)