From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
From: Bartosz Sosnowski <bartosz@janeasystems.com>
Date: Thu, 11 Jul 2019 12:45:38 +0200
Subject: win, fs: mkdir return UV_EINVAL for invalid names
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Makes uv_fs_mkdir return UV_EINVAL for invalid filenames instead of
UV_ENOENT.

Ref: https://github.com/nodejs/node/issues/28599

PR-URL: https://github.com/libuv/libuv/pull/2375
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Saúl Ibarra Corretgé <saghul@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>

diff --git a/deps/uv/src/win/fs.c b/deps/uv/src/win/fs.c
index 9e2f084c8d0e9c0cc60cf5010bdc396bf5eb22e5..088191320cc671a8bc6ae45f07b3b05f95b01b08 100644
--- a/deps/uv/src/win/fs.c
+++ b/deps/uv/src/win/fs.c
@@ -850,8 +850,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_);
+  }
 }
 
 
diff --git a/deps/uv/test/test-fs.c b/deps/uv/test/test-fs.c
index c3153c717b7cd391f71b6184d62e4ee55841591b..fb64ae6b037be591a30a63d9e5450dcfd48e3bdc 100644
--- a/deps/uv/test/test-fs.c
+++ b/deps/uv/test/test-fs.c
@@ -3815,4 +3815,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
diff --git a/deps/uv/test/test-list.h b/deps/uv/test/test-list.h
index 8886b07c8a74736208d5614257f832f59d79633a..29e9cbf85df3f07dd3a017ffca1cea0b56e76b89 100644
--- a/deps/uv/test/test-list.h
+++ b/deps/uv/test/test-list.h
@@ -372,6 +372,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)
@@ -957,6 +958,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)
