]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Use configured umask for command line operations like --zero-stats
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 27 Oct 2022 20:23:50 +0000 (22:23 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 28 Oct 2022 18:07:34 +0000 (20:07 +0200)
Closes #1197.

src/UmaskScope.hpp
src/core/mainoptions.cpp
test/suites/base.bash

index 02bf8e8cbf562201950b8e6fbd0b0080cf2b717e..d141ad30dddbf258ef8f8ddc33c7c345a1a44b1e 100644 (file)
@@ -31,6 +31,8 @@ public:
   UmaskScope(std::optional<mode_t> new_umask);
   ~UmaskScope();
 
+  void release();
+
 private:
   std::optional<mode_t> m_saved_umask = std::nullopt;
 };
@@ -47,6 +49,12 @@ inline UmaskScope::UmaskScope(std::optional<mode_t> new_umask)
 }
 
 inline UmaskScope::~UmaskScope()
+{
+  release();
+}
+
+inline void
+UmaskScope::release()
 {
 #ifndef _WIN32
   if (m_saved_umask) {
@@ -59,6 +67,7 @@ inline UmaskScope::~UmaskScope()
 #  if defined(__GNUC__) && !defined(__clang__)
 #    pragma GCC diagnostic pop
 #  endif
+    m_saved_umask = std::nullopt;
   }
 #endif
 }
index 30afaa4884d4d169b9045093c3fc006c6a1ad4ff..1f6e651cc58fe8f96015762fc654ae96d191fd5e 100644 (file)
@@ -24,6 +24,7 @@
 #include <Hash.hpp>
 #include <InodeCache.hpp>
 #include <ProgressBar.hpp>
+#include <UmaskScope.hpp>
 #include <ccache.hpp>
 #include <core/CacheEntry.hpp>
 #include <core/Manifest.hpp>
@@ -424,6 +425,8 @@ process_main_options(int argc, const char* const* argv)
     Config config;
     config.read();
 
+    UmaskScope umask_scope(config.umask());
+
     const std::string arg = optarg ? optarg : std::string();
 
     switch (c) {
@@ -462,6 +465,7 @@ process_main_options(int argc, const char* const* argv)
     }
 
     case EXTRACT_RESULT: {
+      umask_scope.release(); // Use original umask for files outside cache dir
       const auto cache_entry_data = read_from_path_or_stdin(arg);
       if (!cache_entry_data) {
         PRINT(stderr, "Error: \"{}\"", cache_entry_data.error());
index 67a5d42aef9b1605f449041df80e71b1b1cee0d4..0ce9ce6e1d080d46866fcfa7f8974740b5288edd 100644 (file)
@@ -1069,6 +1069,24 @@ if ! $HOST_OS_WINDOWS; then
     export CCACHE_UMASK=002
     export CCACHE_TEMPDIR=$CCACHE_DIR/tmp
 
+    $CCACHE -C
+    expect_perm "$CCACHE_DIR" drwxrwxr-x
+    expect_perm "$CCACHE_DIR/0" drwxrwxr-x
+    expect_perm "$CCACHE_DIR/0/stats" -rw-rw-r--
+    rm -rf $CCACHE_DIR
+
+    $CCACHE -c
+    expect_perm "$CCACHE_DIR" drwxrwxr-x
+    expect_perm "$CCACHE_DIR/0" drwxrwxr-x
+    expect_perm "$CCACHE_DIR/0/stats" -rw-rw-r--
+    rm -rf $CCACHE_DIR
+
+    $CCACHE -z
+    expect_perm "$CCACHE_DIR" drwxrwxr-x
+    expect_perm "$CCACHE_DIR/0" drwxrwxr-x
+    expect_perm "$CCACHE_DIR/0/stats" -rw-rw-r--
+    rm -rf $CCACHE_DIR
+
     cat <<EOF >test.c
 int main() {}
 EOF