-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

According to Pierre A. Humblet on 5/2/2005 9:22 PM:
> According to the Cygwin Faq,
> 
> *********
> Why doesn't `mkdir -p' work on a network share?
> Unfortunately, you cannot do something like this: 
> 
> bash$ mkdir -p //MACHINE/Share/path/to/new/dir
> mkdir: cannot create directory `//MACHINE': No such file or directory
> 
> This is because mkdir checks for the existence of each directory on the path,
> creating them as necessary. Since `//MACHINE' is not a directory (you can't cd
> to it either), mkdir tries to create it, and fails. 
> **********
> 
> This behavior would be fine with me, but the latest mkdir (GNU coreutils)
> 5.3.0
> creates /MACHINE/Share/path/to/new/dir and returns 0
> 
> Pierre
> 

It appears you have uncovered an upstream bug - in line 210 of CVS
coreutils/lib/makepath.c (unchanged from 5.3.0), `mkdir -p' is attempting
an optimization by blindly changing directory to / if the first character
is '/', without regards to whether there is a leading // such that
changing to / violates POSIX naming semantics.  In my opinion, it should
be possible to rewrite the algorithm to make even your test case works,
eliminating the cygwin FAQ entry:  rather than starting at the left and
making sure each path component exists, the algorithm could start at the
right and successively prune each rightmost component until it no longer
gets ENOENT (or gets to the empty string), then build back up from that
point.  Then, even though //MACHINE does not resolve to a directory,
`mkdir -p //MACHINE/Share/existing/nonexisting' only has to check whether
//MACHINE/Share/existing exists, and create nonexisting from there, rather
than starting all the way from the problematic /, //, or //MACHINE.  The
only drawback to this approach is that it would then require up to n
stat() calls to decide where to start making directories, each processing
O(n) names, which is the exact O(n^2) syscall overhead that the code was
optimized to try to avoid by starting blindly at the leftmost component.
The only other approach I can think of is to special case leading // (at
least on cygwin, leading // should start after //MACHINE/Share/), but not
all POSIX-compliant hosts have the same semantics for leading //, so I
don't know how well such a special case would fold into upstream coreutils.

- --
Life is short - so eat dessert first!

Eric Blake             [EMAIL PROTECTED]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.0 (Cygwin)
Comment: Public key at home.comcast.net/~ericblake/eblake.gpg
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iD4DBQFCd3cZ84KuGfSFAYARAqf8AJ4waeVK7NWOh0D4fz84LD5jcBmPpQCY9blL
6lOcqZkvuNWndvgAjElQ9A==
=sDhN
-----END PGP SIGNATURE-----


_______________________________________________
Bug-coreutils mailing list
Bug-coreutils@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-coreutils

Reply via email to