Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fs: set path when mkdir recursive called on file #31607

Closed
wants to merge 1 commit into from
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
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
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