Skip to content

Commit

Permalink
fs: set path when mkdir recursive called on file
Browse files Browse the repository at this point in the history
PR-URL: #31607
Fixes: #28015
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
  • Loading branch information
bcoe authored and codebytere committed Mar 15, 2020
1 parent 0641b19 commit 7a88f7e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1234,6 +1234,7 @@ int MKDirpSync(uv_loop_t* loop,
}
break;
case UV_EACCES:
case UV_ENOTDIR:
case UV_EPERM: {
return err;
}
Expand Down Expand Up @@ -1309,6 +1310,7 @@ int MKDirpAsync(uv_loop_t* loop,
break;
}
case UV_EACCES:
case UV_ENOTDIR:
case UV_EPERM: {
req_wrap->continuation_data()->Done(err);
break;
Expand Down Expand Up @@ -1351,7 +1353,6 @@ int MKDirpAsync(uv_loop_t* loop,
}
// verify that the path pointed to is actually a directory.
if (err == 0 && !S_ISDIR(req->statbuf.st_mode)) err = UV_EEXIST;
uv_fs_req_cleanup(req);
req_wrap->continuation_data()->Done(err);
}});
if (err < 0) req_wrap->continuation_data()->Done(err);
Expand Down
6 changes: 6 additions & 0 deletions test/parallel/test-fs-mkdir.js
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,7 @@ function nextdir() {
message: /ENOTDIR: .*mkdir/,
name: 'Error',
syscall: 'mkdir',
path: pathname // See: https://github.com/nodejs/node/issues/28015
}
);
}
Expand Down Expand Up @@ -187,6 +188,11 @@ function nextdir() {
assert.strictEqual(err.code, 'ENOTDIR');
assert.strictEqual(err.syscall, 'mkdir');
assert.strictEqual(fs.existsSync(pathname), false);
// See: https://github.com/nodejs/node/issues/28015
// The path field varies slightly in Windows errors, vs., other platforms
// see: https://github.com/libuv/libuv/issues/2661, for this reason we
// use startsWith() rather than comparing to the full "pathname".
assert(err.path.startsWith(filename));
}));
}

Expand Down

0 comments on commit 7a88f7e

Please sign in to comment.