On 11 Sep 2003 Martin Pool <[EMAIL PROTECTED]> wrote:

> On 10 Sep 2003 Lisa Seelye <[EMAIL PROTECTED]> wrote:
> 
> > Since I forgot to cc the list last week, here goes:
> 
> Sorry I didn't get to it.
> 
> > Attached is a patch to address some problems I have had locally; it
> > does two things:
> > 
> > First: It allows for a "mkdir -p" like dcc_mkdir() to create
> > directories recursivly.

Common subdirectories: cvs/src/CVS and cvs-diff/src/CVS
diff -uN cvs/src/tempfile.c cvs-diff/src/tempfile.c
--- cvs/src/tempfile.c  2003-08-30 13:13:09.000000000 -0400
+++ cvs-diff/src/tempfile.c     2003-09-04 16:12:50.000000000 -0400
@@ -105,15 +105,27 @@
 /**
  * Create the directory @p path.  If it already exists as a directory
  * we succeed.
+ * Recursive mkdir is from the Gal project's e_mkdir_hier() function.
  **/
 int dcc_mkdir(const char *path)
 {
-    if ((mkdir(path, 0755) == -1) && (errno != EEXIST)) {
-        rs_log_error("mkdir %s failed: %s", path, strerror(errno));
-        return EXIT_IO_ERROR;
-    }
+       char *copy, *p;
 
-    return 0;
+       p = copy = strdup(path);
+       do {
+               p = strchr (p + 1, '/');
+               if (p)
+                       *p = '\0';
+               if (access (copy, F_OK) == -1) {
+                       if (mkdir (copy, 0755) == -1) {
+                               rs_log_error("mkdir %s failed: %s", path, 
strerror(errno));
+                               return EXIT_IO_ERROR;
+                       }
+               }
+               if (p)
+                       *p = '/';
+       } while (p);
+       return 0;
 }

The access() is a bit redundant.  I would probably try just doing the
mkdir(), and ignoring EEXIST, as in the previous code.  This is a good
Unix idiom (imho) for "make sure this is a directory".

In fact I think your version has the problem that if the name exists
but is not a directory, it will succeed when it should have failed.

Also you should free(copy) when you're done.

-- 
Martin 
__ 
distcc mailing list            http://distcc.samba.org/
To unsubscribe or change options: 
http://lists.samba.org/cgi-bin/mailman/listinfo/distcc

Reply via email to