[libcxx] r273048 - Respect the processes umask in the create_directory test

Eric Fiselier via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 17 13:54:26 PDT 2016


Author: ericwf
Date: Fri Jun 17 15:54:25 2016
New Revision: 273048

URL: http://llvm.org/viewvc/llvm-project?rev=273048&view=rev
Log:
Respect the processes umask in the create_directory test

Modified:
    libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp

Modified: libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp
URL: http://llvm.org/viewvc/llvm-project/libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp?rev=273048&r1=273047&r2=273048&view=diff
==============================================================================
--- libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp (original)
+++ libcxx/trunk/test/std/experimental/filesystem/fs.op.funcs/fs.op.create_directory/create_directory.pass.cpp Fri Jun 17 15:54:25 2016
@@ -26,9 +26,18 @@
 #include "rapid-cxx-test.hpp"
 #include "filesystem_test_helper.hpp"
 
+#include <sys/types.h>
+#include <sys/stat.h>
+
 using namespace std::experimental::filesystem;
 namespace fs = std::experimental::filesystem;
 
+fs::perms read_umask() {
+    mode_t old_mask = umask(0);
+    umask(old_mask); // reset the mask to the old value.
+    return static_cast<fs::perms>(old_mask);
+}
+
 TEST_SUITE(filesystem_create_directory_test_suite)
 
 TEST_CASE(test_signatures)
@@ -68,15 +77,8 @@ TEST_CASE(create_directory_one_level)
     TEST_CHECK(is_directory(dir));
 
     auto st = status(dir);
-    perms owner_perms = perms::owner_all;
-    perms gperms = perms::group_all;
-    perms other_perms = perms::others_read | perms::others_exec;
-#if defined(__APPLE__) || defined(__FreeBSD__)
-    gperms = perms::group_read | perms::group_exec;
-#endif
-    TEST_CHECK((st.permissions() & perms::owner_all) == owner_perms);
-    TEST_CHECK((st.permissions() & perms::group_all) == gperms);
-    TEST_CHECK((st.permissions() & perms::others_all) == other_perms);
+    const perms expect_perms = perms::all & ~(read_umask());
+    TEST_CHECK((st.permissions() & perms::all) == expect_perms);
 }
 
 TEST_CASE(create_directory_multi_level)




More information about the cfe-commits mailing list