Create directory with 0777 mode in make_directory

Fixes #408
This commit is contained in:
Maxime Coste 2015-09-16 20:04:29 +01:00
parent 693d9a4861
commit c859e8ab5f

View File

@ -304,8 +304,14 @@ void make_directory(StringView dir)
if (not S_ISDIR(st.st_mode))
throw runtime_error(format("Cannot make directory, '{}' exists but is not a directory", dirname));
}
else if (mkdir(dirname.zstr(), S_IRWXU) != 0)
throw runtime_error(format("mkdir failed for directory '{}' errno {}", dirname, errno));
else
{
auto old_mask = umask(0);
auto restore_mask = on_scope_end([old_mask]() { umask(old_mask); });
if (mkdir(dirname.zstr(), S_IRWXU | S_IRWXG | S_IRWXO) != 0)
throw runtime_error(format("mkdir failed for directory '{}' errno {}", dirname, errno));
}
}
}