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

Corinna Vinschen corinna-cygwin@cygwin.com
Wed Aug 28 15:18:00 GMT 2019


On Aug 28 16:15, Corinna Vinschen wrote:
> 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)))

One problem here is, what to do about border cases like

  $ mkdir a\/\/\/

In theory slashes and backslashes should both be treated as dir
separators.  Handling a case like this so that all expectations
are satisfied is next to impossible, I guess.


Corinna

-- 
Corinna Vinschen
Cygwin Maintainer
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 833 bytes
Desc: not available
URL: <http://cygwin.com/pipermail/cygwin/attachments/20190828/4b9b222e/attachment.sig>


More information about the Cygwin mailing list