Subject: Re: mkdir -p and network drives
From: Paul Eggert <[email-masked]>
To: Eric Blake <[email-masked]>
Cc: "Pierre A. Humblet" <[email-masked]>, [email-masked], [email-masked]
Date: Thu, 05 May 2005 01:09:24 -0700

Eric Blake <[email-masked]> writes:

> The only other approach I can think of is to special case leading // (at
> least on cygwin, leading // should start after //MACHINE/Share/)

What happens with the file names "//", "//MACHINE", and
"//MACHINE/Share" in Cygwin?  Don't they appear to be directories,
albeit directories that you can't alter?  If not, that suggests a bug
in Cygwin.

> not all POSIX-compliant hosts have the same semantics for leading //

As far as I know the only extant hosts with this problem are
Windows-based hosts.  Apollo DomainOS
<http://apollo.maxnt.co.jp/apollo/english/> was the only other
example, but it's dead.  I don't know the semantics under the
Windows-based hosts, so I'm not qualified to write a general fix.
(And if it's too complicated, we probably don't want to maintain it.)

That being said, it can't hurt to add the following minor workaround,
(which would work on Domain OS anyway :-), so I installed it.

2005-05-05  Paul Eggert  <[email-masked]>

	* makepath.c (make_path): chdir to "//", not "/", if the file name
	starts with exactly two slashes.  This doesn't solve the problem
	in general but it's better than nothing.  Problem reported by
	Pierre A. Humblet via Eric Blake.

--- makepath.c.~1.60.~	2004-07-30 13:29:01 -0700
+++ makepath.c	2005-05-05 00:54:19 -0700
@@ -207,8 +207,14 @@ make_path (const char *argpath,
       /* If we've saved the cwd and DIRPATH is an absolute pathname,
 	 we must chdir to `/' in order to enable the chdir optimization.
          So if chdir ("/") fails, turn off the optimization.  */
-      if (do_chdir && *dirpath == '/' && chdir ("/") < 0)
-	do_chdir = false;
+      if (do_chdir && dirpath[0] == '/')
+	{
+	  /* POSIX says "//" might be special, so chdir to "//" if the
+	     file name starts with exactly two slashes.  */
+	  char const *root = "//" + (dirpath[1] != '/' || dirpath[2] == '/');
+	  if (chdir (root) != 0)
+	    do_chdir = false;
+	}
 
       slash = dirpath;

--
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/