This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Odd, is it not? mkdir 'e:\' cannot be undone by rmdir 'e:\' ...


On Aug 28 08:36, Eric Blake wrote:
> On 8/28/19 7:59 AM, Corinna Vinschen wrote:
> 
> >>>>> mkdir(2) has some special code from 2009 which drops trailing
> >>>>> {back}slashes to perform a bordercase in mkdir Linux-compatible.
> >>>>> This code snippet doesn't exist in rmdir(2).
> 
> Dropping trailing slashes to be Linux-compatible is okay.  Dropping
> trailing backslashes is risky, though, if it makes us forget that the
> user was asking for a DOS path (even though DOS paths are not always
> going to work as expected).
> 
> 
> > 
> > Eric, any insight?  As usual our comments from way back when are lacking
> > in terms of what exact problem this code is trying to fix/workaround.
> 
> If I recall, we had cases where 'mkdir a/' and 'mkdir a' did not behave
> identically, even though POSIX says they should; compounded by the fact
> that Windows treats trailing slash differently when performing native
> mkdir on a drive than it does on a subdirectory of a drive.
> 
> It may be as simple as changing the isdirsep() from the identified
> commit to instead check only for '/' (and ignore '\').

As simple as that?

diff --git a/winsup/cygwin/dir.cc b/winsup/cygwin/dir.cc
index b757851d5c7f..747b1582af50 100644
--- a/winsup/cygwin/dir.cc
+++ b/winsup/cygwin/dir.cc
@@ -314,13 +314,13 @@ mkdir (const char *dir, mode_t mode)
 	  set_errno (ENOENT);
 	  __leave;
 	}
-      if (isdirsep (dir[strlen (dir) - 1]))
+      if (dir[strlen (dir) - 1] == '/')
 	{
 	  /* This converts // to /, but since both give EEXIST, we're okay.  */
 	  char *buf;
 	  char *p = stpcpy (buf = tp.c_get (), dir) - 1;
 	  dir = buf;
-	  while (p > dir && isdirsep (*p))
+	  while (p > dir && *p == '/')
 	    *p-- = '\0';
 	}
       if (!(fh = build_fh_name (dir, PC_SYM_NOFOLLOW)))


Thanks,
Corinna

-- 
Corinna Vinschen
Cygwin Maintainer

Attachment: signature.asc
Description: PGP signature


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]