Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <42777719.8090103@byu.net> Date: Tue, 03 May 2005 07:05:29 -0600 From: Eric Blake User-Agent: Mozilla Thunderbird 1.0.2 (Windows/20050317) MIME-Version: 1.0 To: "Pierre A. Humblet" CC: cygwin AT cygwin DOT com, bug-coreutils AT gnu DOT org Subject: Re: mkdir -p and network drives References: <3 DOT 0 DOT 5 DOT 32 DOT 20050502232204 DOT 00b52180 AT incoming DOT verizon DOT net> In-Reply-To: <3.0.5.32.20050502232204.00b52180@incoming.verizon.net> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-IsSubscribed: yes -----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 ebb9 AT byu DOT net -----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----- -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/