`mkdir -p' would create parent directories with permissions
authorJim Meyering <jim@meyering.net>
Tue, 31 Oct 2000 19:25:50 +0000 (19:25 +0000)
committerJim Meyering <jim@meyering.net>
Tue, 31 Oct 2000 19:25:50 +0000 (19:25 +0000)
that did not account for the umask. [introduced with the
2000-09-30 change that became part of fileutils-4.0.28]

Include dirname.h.
Compute the parent directory `mode' unconditionally, effectively
as `$(umask -S),u+wx'.
Use make_path to create only the parent directories, thus using
the same code, both with and without -p, to create the final
component in each file name.  Reported by Bob Proulx.

src/mkdir.c

index 5309f12..92d158c 100644 (file)
@@ -23,6 +23,7 @@
 #include <sys/types.h>
 
 #include "system.h"
+#include "dirname.h"
 #include "error.h"
 #include "makepath.h"
 #include "modechange.h"
@@ -120,6 +121,12 @@ main (int argc, char **argv)
     }
 
   newmode = S_IRWXUGO;
+  {
+    mode_t umask_value = umask (0);
+    umask (umask_value);               /* Restore the old value. */
+    parent_mode = (newmode & (~ umask_value)) | S_IWUSR | S_IXUSR;
+  }
+
   if (specified_mode)
     {
       struct mode_change *change = mode_compile (specified_mode, 0);
@@ -130,17 +137,19 @@ main (int argc, char **argv)
        xalloc_die ();
       newmode = mode_adjust (newmode, change);
     }
-  parent_mode = S_IWUSR | S_IXUSR | newmode;
 
   for (; optind < argc; ++optind)
     {
       int fail = 0;
       if (create_parents)
        {
-         fail = make_path (argv[optind], newmode, parent_mode,
+         const char *parents = dir_name (argv[optind]);
+         fail = make_path (parents, parent_mode, parent_mode,
                            -1, -1, 1, verbose_fmt_string);
+         free (dir_name);
        }
-      else
+
+      if (fail == 0)
        {
          fail = mkdir (argv[optind], newmode);
          if (fail)