]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Extract get_umask function to Util
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 19 Feb 2022 15:52:26 +0000 (16:52 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 19 Feb 2022 15:52:26 +0000 (16:52 +0100)
src/TemporaryFile.cpp
src/Util.cpp
src/Util.hpp

index 8c9e3868d694a0cdc1d6ac3d9bdb5958ca198f9e..3b6ccabd15d66e2566853a4785bc111e6f03e8e8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 using nonstd::string_view;
 
-namespace {
-
-#ifndef _WIN32
-mode_t
-get_umask()
-{
-  static bool mask_retrieved = false;
-  static mode_t mask;
-  if (!mask_retrieved) {
-    mask = umask(0);
-    umask(mask);
-    mask_retrieved = true;
-  }
-  return mask;
-}
-#endif
-
-} // namespace
-
 TemporaryFile::TemporaryFile(string_view path_prefix)
   : path(std::string(path_prefix) + ".XXXXXX")
 {
@@ -69,6 +50,6 @@ TemporaryFile::TemporaryFile(string_view path_prefix)
 
   Util::set_cloexec_flag(*fd);
 #ifndef _WIN32
-  fchmod(*fd, 0666 & ~get_umask());
+  fchmod(*fd, 0666 & ~Util::get_umask());
 #endif
 }
index 55254489bee1e22757da8b1afeca4e206a805c08..f9636dbc52a7738ef5a951c001e21fe4631b2d58 100644 (file)
@@ -742,6 +742,21 @@ get_relative_path(string_view dir, string_view path)
   return result.empty() ? "." : result;
 }
 
+#ifndef _WIN32
+mode_t
+get_umask()
+{
+  static bool mask_retrieved = false;
+  static mode_t mask;
+  if (!mask_retrieved) {
+    mask = umask(0);
+    umask(mask);
+    mask_retrieved = true;
+  }
+  return mask;
+}
+#endif
+
 void
 hard_link(const std::string& oldpath, const std::string& newpath)
 {
index 67cd164e43e6ce417aa5761aad5307bad47a903f..6e0aea833453a7d268df63ddfd4ba6118d48c214 100644 (file)
@@ -188,6 +188,11 @@ const char* get_hostname();
 std::string get_relative_path(nonstd::string_view dir,
                               nonstd::string_view path);
 
+#ifndef _WIN32
+// Get process umask.
+mode_t get_umask();
+#endif
+
 // Hard-link `oldpath` to `newpath`. Throws `core::Error` on error.
 void hard_link(const std::string& oldpath, const std::string& newpath);