diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2022-06-07 16:53:44 +0200 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2022-08-20 13:33:12 +0200 |
commit | 8294d99c547d952d9d0fa1fff607eb7dfd9f9f7d (patch) | |
tree | 3c0a747e2f1cbb24f351bbe1a546b9e56a09636a | |
parent | 87cbd482009c2fabc62ae68e18d77ffbaa02b04f (diff) | |
download | ccache-8294d99c547d952d9d0fa1fff607eb7dfd9f9f7d.tar.gz |
fix: Use correct umask when populating primary cache from secondary
Util::get_umask retrieves the process's umask and caches it to avoid
some system calls. This doesn't interact well now when using UmaskScope
to change umask temporarily since Util::get_umask then only sometimes
returns the correct value. This leads to the incorrect umask being used
when writing cache entries to the primary storage for secondary storage
hits.
Fix this by not caching the umask system call.
Closes #1087.
(cherry picked from commit 6484cdfa0f22214d91cd61562f48d4d9060d2533)
-rw-r--r-- | src/Util.cpp | 11 | ||||
-rw-r--r-- | src/Util.hpp | 2 | ||||
-rw-r--r-- | test/suites/secondary_file.bash | 16 |
3 files changed, 12 insertions, 17 deletions
diff --git a/src/Util.cpp b/src/Util.cpp index abbf76d3..8898337f 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -747,20 +747,13 @@ 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; - } + const mode_t mask = umask(0); + umask(mask); return mask; } -#endif void hard_link(const std::string& oldpath, const std::string& newpath) diff --git a/src/Util.hpp b/src/Util.hpp index 4ddffa34..d0c58b86 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -188,10 +188,8 @@ 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); diff --git a/test/suites/secondary_file.bash b/test/suites/secondary_file.bash index 3c539874..1a688625 100644 --- a/test/suites/secondary_file.bash +++ b/test/suites/secondary_file.bash @@ -167,18 +167,22 @@ SUITE_secondary_file() { # ------------------------------------------------------------------------- TEST "umask" - CCACHE_SECONDARY_STORAGE="file://$PWD/secondary|umask=022" + export CCACHE_UMASK=042 + CCACHE_SECONDARY_STORAGE="file://$PWD/secondary|umask=024" rm -rf secondary $CCACHE_COMPILE -c test.c - expect_perm secondary drwxr-xr-x - expect_perm secondary/CACHEDIR.TAG -rw-r--r-- + expect_perm secondary drwxr-x-wx # 777 & 024 + expect_perm secondary/CACHEDIR.TAG -rw-r---w- # 666 & 024 + result_file=$(find $CCACHE_DIR -name '*R') + expect_perm "$(dirname "${result_file}")" drwx-wxr-x # 777 & 042 + expect_perm "${result_file}" -rw--w-r-- # 666 & 042 - CCACHE_SECONDARY_STORAGE="file://$PWD/secondary|umask=000" + CCACHE_SECONDARY_STORAGE="file://$PWD/secondary|umask=026" $CCACHE -C >/dev/null rm -rf secondary $CCACHE_COMPILE -c test.c - expect_perm secondary drwxrwxrwx - expect_perm secondary/CACHEDIR.TAG -rw-rw-rw- + expect_perm secondary drwxr-x--x # 777 & 026 + expect_perm secondary/CACHEDIR.TAG -rw-r----- # 666 & 026 # ------------------------------------------------------------------------- TEST "Sharding" |