From 602ca8c8b1971077943e1abe17be4cc7b29b0b5f Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sat, 18 Jun 2022 19:55:02 +0200 Subject: [PATCH] fix: Clean up temporary dir if it's left the default Cleanup of the temporary directory is done if it is $CCACHE_DIR/tmp, which used to be the default until [1] where the default was changed to /run/user/$UID/ccache-tmp. Improve this so that cleanup happens if the temporary directory is equal to the default regardless of the default. [1]: 213d9883a0c3944749f8512eeb784d8572ad8d91 (cherry picked from commit ce6b0c3dbdf1f84ab625d4c86770297f93b87032) --- src/Config.cpp | 4 ++-- src/Config.hpp | 6 +++--- src/storage/primary/PrimaryStorage.cpp | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Config.cpp b/src/Config.cpp index ee4cd9f7f..22c5cc0e6 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -1037,7 +1037,7 @@ Config::check_key_tables_consistency() } std::string -Config::default_temporary_dir(const std::string& cache_dir) +Config::default_temporary_dir() const { static const std::string run_user_tmp_dir = [] { #ifdef HAVE_GETEUID @@ -1048,5 +1048,5 @@ Config::default_temporary_dir(const std::string& cache_dir) #endif return std::string(); }(); - return !run_user_tmp_dir.empty() ? run_user_tmp_dir : cache_dir + "/tmp"; + return !run_user_tmp_dir.empty() ? run_user_tmp_dir : m_cache_dir + "/tmp"; } diff --git a/src/Config.hpp b/src/Config.hpp index 6275fa659..a9e08eca3 100644 --- a/src/Config.hpp +++ b/src/Config.hpp @@ -91,6 +91,8 @@ public: // Return true for MSVC (cl.exe) and clang-cl. bool is_compiler_group_msvc() const; + std::string default_temporary_dir() const; + void set_base_dir(const std::string& value); void set_cache_dir(const std::string& value); void set_compiler(const std::string& value); @@ -198,8 +200,6 @@ private: const nonstd::optional& env_var_key, bool negate, const std::string& origin); - - static std::string default_temporary_dir(const std::string& cache_dir); }; inline bool @@ -479,7 +479,7 @@ Config::set_cache_dir(const std::string& value) { m_cache_dir = value; if (!m_temporary_dir_configured_explicitly) { - m_temporary_dir = default_temporary_dir(m_cache_dir); + m_temporary_dir = default_temporary_dir(); } } diff --git a/src/storage/primary/PrimaryStorage.cpp b/src/storage/primary/PrimaryStorage.cpp index 7ba213763..3584776d7 100644 --- a/src/storage/primary/PrimaryStorage.cpp +++ b/src/storage/primary/PrimaryStorage.cpp @@ -99,7 +99,7 @@ PrimaryStorage::initialize() { MTR_SCOPE("primary_storage", "clean_internal_tempdir"); - if (m_config.temporary_dir() == m_config.cache_dir() + "/tmp") { + if (m_config.temporary_dir() == m_config.default_temporary_dir()) { clean_internal_tempdir(); } } -- 2.47.2