Skip to content

Commit

Permalink
win, fs: mkdir return UV_EINVAL for invalid names
Browse files Browse the repository at this point in the history
Makes uv_fs_mkdir return UV_EINVAL for invalid filenames instead of
UV_ENOENT.

Ref: nodejs/node#28599

PR-URL: libuv#2375
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Saúl Ibarra Corretgé <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
  • Loading branch information
bzoz committed Jul 16, 2019
1 parent 2c27950 commit ecff278
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/win/fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1180,8 +1180,13 @@ void fs__unlink(uv_fs_t* req) {

void fs__mkdir(uv_fs_t* req) {
/* TODO: use req->mode. */
int result = _wmkdir(req->file.pathw);
SET_REQ_RESULT(req, result);
req->result = _wmkdir(req->file.pathw);
if (req->result == -1) {
req->sys_errno_ = _doserrno;
req->result = req->sys_errno_ == ERROR_INVALID_NAME
? UV_EINVAL
: uv_translate_sys_error(req->sys_errno_);
}
}


Expand Down
12 changes: 12 additions & 0 deletions test/test-fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4060,4 +4060,16 @@ TEST_IMPL(fs_fchmod_archive_readonly) {

return 0;
}

TEST_IMPL(fs_invalid_mkdir_name) {
uv_loop_t* loop;
uv_fs_t req;
int r;

loop = uv_default_loop();
r = uv_fs_mkdir(loop, &req, "invalid>", 0, NULL);
ASSERT(r == UV_EINVAL);

return 0;
}
#endif
2 changes: 2 additions & 0 deletions test/test-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ TEST_DECLARE (fs_exclusive_sharing_mode)
TEST_DECLARE (fs_file_flag_no_buffering)
TEST_DECLARE (fs_open_readonly_acl)
TEST_DECLARE (fs_fchmod_archive_readonly)
TEST_DECLARE (fs_invalid_mkdir_name)
#endif
TEST_DECLARE (strscpy)
TEST_DECLARE (threadpool_queue_work_simple)
Expand Down Expand Up @@ -973,6 +974,7 @@ TASK_LIST_START
TEST_ENTRY (fs_file_flag_no_buffering)
TEST_ENTRY (fs_open_readonly_acl)
TEST_ENTRY (fs_fchmod_archive_readonly)
TEST_ENTRY (fs_invalid_mkdir_name)
#endif
TEST_ENTRY (get_osfhandle_valid_handle)
TEST_ENTRY (open_osfhandle_valid_handle)
Expand Down

0 comments on commit ecff278

Please sign in to comment.