Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
fs: set path when mkdir recursive called on file
Fixes: #28015
  • Loading branch information
bcoe committed Feb 2, 2020
commit 78a48fbf279b97dd4ff7277564f143911060f6f6
3 changes: 2 additions & 1 deletion src/node_file.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1278,6 +1278,7 @@ int MKDirpSync(uv_loop_t* loop,
}
break;
case UV_EACCES:
case UV_ENOTDIR:
case UV_EPERM: {
return err;
}
Expand Down Expand Up @@ -1356,6 +1357,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 @@ -1398,7 +1400,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);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We were calling uv_fs_req_cleanup prematurely on Windows systems, and freeing req->path.

uv_fs_req_cleanup is called in FSReqAfterScope::~FSReqAfterScope().

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