summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2005-10-24 10:03:47 +0000
committerJim Meyering <jim@meyering.net>2005-10-24 10:03:47 +0000
commit5b427ce7c37a517695b30a415c14dace633da6b4 (patch)
treee509c6b69f8165323c07267f8e66dd538bf984da /lib
parentce44b29901cf2de25af72b653997a1f8e56459cb (diff)
downloadcoreutils-5b427ce7c37a517695b30a415c14dace633da6b4.tar.xz
A command like `mkdir -p nonexistent/.' would create the
directory but exit nonzero with a diagnostic. This could also be triggered with a non-`.' component, e.g., in a race with another process running the same `mkdir -p nonexistent/sub' command. (make_dir_parents): Handle the case of an existing final component. Reported by Matthias Andree here: http://savannah.gnu.org/bugs/?func=detailitem&item_id=14848
Diffstat (limited to 'lib')
-rw-r--r--lib/mkdir-p.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/lib/mkdir-p.c b/lib/mkdir-p.c
index 7c3965f3e..ac2e28749 100644
--- a/lib/mkdir-p.c
+++ b/lib/mkdir-p.c
@@ -264,17 +264,25 @@ make_dir_parents (char const *arg,
Create the final component of the file name. */
if (retval)
{
- if (mkdir (basename_dir, mode) != 0)
- {
- error (0, errno, _("cannot create directory %s"), quote (dir));
- retval = false;
- }
- else
+ bool just_created = (mkdir (basename_dir, mode) == 0);
+ if (just_created)
{
if (verbose_fmt_string)
error (0, 0, verbose_fmt_string, quote (dir));
fixup_permissions_dir = basename_dir;
}
+ else
+ {
+ if (errno != EEXIST)
+ {
+ error (0, errno, _("cannot create directory %s"), quote (dir));
+ retval = false;
+ }
+ else
+ {
+ /* The directory already exists. Do nothing. */
+ }
+ }
}
}