summaryrefslogtreecommitdiff
path: root/src/mkdir.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-10-31 19:25:50 +0000
committerJim Meyering <jim@meyering.net>2000-10-31 19:25:50 +0000
commitc8da0cbba68139e51a274039e126d443d4eababf (patch)
tree763797695f7df69a57c215de877878fa146802d1 /src/mkdir.c
parent575f5c2f24466f77133993f62aeef5c54f0cfefb (diff)
downloadcoreutils-c8da0cbba68139e51a274039e126d443d4eababf.tar.xz
`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.
Diffstat (limited to 'src/mkdir.c')
-rw-r--r--src/mkdir.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/mkdir.c b/src/mkdir.c
index 5309f120f..92d158c63 100644
--- a/src/mkdir.c
+++ b/src/mkdir.c
@@ -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)