From: Jim Meyering Date: Tue, 31 Oct 2000 19:25:50 +0000 (+0000) Subject: `mkdir -p' would create parent directories with permissions X-Git-Tag: FILEUTILS-4_0_30~10 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=c8da0cbba68139e51a274039e126d443d4eababf;p=thirdparty%2Fcoreutils.git `mkdir -p' would create parent directories with permissions 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. --- diff --git a/src/mkdir.c b/src/mkdir.c index 5309f120f8..92d158c63b 100644 --- a/src/mkdir.c +++ b/src/mkdir.c @@ -23,6 +23,7 @@ #include #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)