[PATCH] mkdir: always check-for-existence
Ben
cygwin@wijen.net
Mon Jun 3 20:07:00 GMT 2019
When creating a directory which already exists, NtCreateFile will correctly
return 'STATUS_OBJECT_NAME_COLLISION'.
However when creating a directory and all its parents a normal use would
be to start with mkdir(â/cygdrive/câ) which translates to âC:\â for
which it'll
instead return âSTATUS_ACCESS_DENIEDâ.
So we better check for existence prior to calling NtCreateFile.
---
 winsup/cygwin/dir.cc | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc
index f43eae461..b757851d5 100644
--- a/winsup/cygwin/dir.cc
+++ b/winsup/cygwin/dir.cc
@@ -331,8 +331,10 @@ mkdir (const char *dir, mode_t mode)
     debug_printf ("got %d error from build_fh_name", fh->error ());
     set_errno (fh->error ());
    }
+Â Â Â Â Â else if (fh->exists ())
+Â Â Â set_errno (EEXIST);
      else if (has_dot_last_component (dir, true))
-Â Â Â set_errno (fh->exists () ? EEXIST : ENOENT);
+Â Â Â set_errno (ENOENT);
      else if (!fh->mkdir (mode))
    res = 0;
      delete fh;
--
2.21.0
More information about the Cygwin-patches
mailing list