diff options
author | Jim Meyering <jim@meyering.net> | 2000-11-05 15:14:09 +0000 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2000-11-05 15:14:09 +0000 |
commit | 9b18c35ac946d538e237a5494fc1626be13db5c6 (patch) | |
tree | 7c7dffb195394ae6d02083413f4c257cb3c3b07f /src | |
parent | 33f1edc571d8b244b7e0352dcc157493f5b6d8f3 (diff) | |
download | coreutils-9b18c35ac946d538e237a5494fc1626be13db5c6.tar.xz |
(main): Use make_dir instead of using mkdir directly.
Diagnose as failure when mkdir tries to create (without the
--parent (-p) option) a directory that already exists.
Diffstat (limited to 'src')
-rw-r--r-- | src/mkdir.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/mkdir.c b/src/mkdir.c index 11487c8f2..bc5ad0e68 100644 --- a/src/mkdir.c +++ b/src/mkdir.c @@ -151,12 +151,22 @@ main (int argc, char **argv) if (fail == 0) { - fail = mkdir (argv[optind], newmode); - if (fail) - error (0, errno, _("cannot create directory %s"), - quote (argv[optind])); + const char *dir = argv[optind]; + int dir_created; + int t_errno; + fail = make_dir (dir, dir, newmode, &dir_created); + t_errno = errno; + /* If make_dir `succeeds' because the directory already exists, + then fail unless --parents (-p) was specified. */ + if (fail || + (!create_parents && !dir_created && (t_errno = EEXIST))) + { + error (0, t_errno, _("cannot create directory %s"), + quote (dir)); + fail = 1; + } else if (verbose_fmt_string) - error (0, 0, verbose_fmt_string, quote (argv[optind])); + error (0, 0, verbose_fmt_string, quote (dir)); /* mkdir(2) is required to honor only the file permission bits. In particular, it needn't do anything about `special' bits, @@ -166,10 +176,10 @@ main (int argc, char **argv) if (fail == 0 && specified_mode) { - fail = chmod (argv[optind], newmode); + fail = chmod (dir, newmode); if (fail) error (0, errno, _("cannot set permissions of directory %s"), - quote (argv[optind])); + quote (dir)); } } |