Skip to content

Commit

Permalink
utils/mkdir-p: check if dir exists also after mkdir failed
Browse files Browse the repository at this point in the history
with "make install -j8" it happens very often that two or more make
instances are creating the same directory in parallel. As a result one
instace creates the directory and second mkdir fails because the
directory exists already (but it did not while testing for it earlier).

Signed-off-by: Sebastian Andrzej Siewior <[email protected]>

Reviewed-by: Matt Caswell <[email protected]>
Reviewed-by: Rich Salz <[email protected]>
(Merged from openssl#1204)
  • Loading branch information
sebastianas authored and Rich Salz committed Jun 23, 2016
1 parent fe2d149 commit 70a56b9
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion util/mkdir-p.pl
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ sub do_mkdir_p {
do_mkdir_p($parent);
}

mkdir($dir, 0777) || die "Cannot create directory $dir: $!\n";
unless (mkdir($dir, 0777)) {
if (-d $dir) {
# We raced against another instance doing the same thing.
return;
}
die "Cannot create directory $dir: $!\n";
}
print "created directory `$dir'\n";
}

0 comments on commit 70a56b9

Please sign in to comment.