From c859e8ab5f45cb650a0b62d8756184d1e2d7bc98 Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Wed, 16 Sep 2015 20:04:29 +0100 Subject: [PATCH] Create directory with 0777 mode in make_directory Fixes #408 --- src/file.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/file.cc b/src/file.cc index 65d01912..9810a3d5 100644 --- a/src/file.cc +++ b/src/file.cc @@ -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)); + } } }