diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2022-10-27 22:23:50 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2022-10-28 20:07:34 +0200 |
commit | 79cb07c0b0f0992092ebef1b3c50b7ac68f6cad2 (patch) | |
tree | 19599374af6fb0db066006a8738c1eebaf14875e | |
parent | 000b49a99bbd6b581b515676d1031ed6bdcfb48a (diff) | |
download | ccache-79cb07c0b0f0992092ebef1b3c50b7ac68f6cad2.tar.gz |
fix: Use configured umask for command line operations like --zero-stats
Closes #1197.
-rw-r--r-- | src/UmaskScope.hpp | 9 | ||||
-rw-r--r-- | src/core/mainoptions.cpp | 4 | ||||
-rw-r--r-- | test/suites/base.bash | 18 |
3 files changed, 31 insertions, 0 deletions
diff --git a/src/UmaskScope.hpp b/src/UmaskScope.hpp index 02bf8e8c..d141ad30 100644 --- a/src/UmaskScope.hpp +++ b/src/UmaskScope.hpp @@ -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; }; @@ -48,6 +50,12 @@ inline UmaskScope::UmaskScope(std::optional<mode_t> new_umask) inline UmaskScope::~UmaskScope() { + release(); +} + +inline void +UmaskScope::release() +{ #ifndef _WIN32 if (m_saved_umask) { // https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80635 @@ -59,6 +67,7 @@ inline UmaskScope::~UmaskScope() # if defined(__GNUC__) && !defined(__clang__) # pragma GCC diagnostic pop # endif + m_saved_umask = std::nullopt; } #endif } diff --git a/src/core/mainoptions.cpp b/src/core/mainoptions.cpp index 30afaa48..1f6e651c 100644 --- a/src/core/mainoptions.cpp +++ b/src/core/mainoptions.cpp @@ -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()); diff --git a/test/suites/base.bash b/test/suites/base.bash index 67a5d42a..0ce9ce6e 100644 --- a/test/suites/base.bash +++ b/test/suites/base.bash @@ -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 |