Merge pull request #1716 from botovq/next

mkdirp: do not throw an error if directory exists
This commit is contained in:
Michael Stapelberg 2015-05-23 13:33:33 +02:00
commit 0d0bde6b1e
1 changed files with 13 additions and 1 deletions

View File

@ -11,7 +11,19 @@
bool mkdirp(const char *path) {
if (mkdir(path, S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH) == 0)
return true;
if (errno != ENOENT) {
if (errno == EEXIST) {
struct stat st;
/* Check that the named file actually is a directory. */
if (stat(path, &st)) {
ELOG("stat(%s) failed: %s\n", path, strerror(errno));
return false;
}
if (!S_ISDIR(st.st_mode)) {
ELOG("mkdir(%s) failed: %s\n", path, strerror(ENOTDIR));
return false;
}
return true;
} else if (errno != ENOENT) {
ELOG("mkdir(%s) failed: %s\n", path, strerror(errno));
return false;
}