]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Clean up temporary dir if it's left the default
authorJoel Rosdahl <joel@rosdahl.net>
Sat, 18 Jun 2022 17:55:02 +0000 (19:55 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 18 Jun 2022 18:08:16 +0000 (20:08 +0200)
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

src/Config.cpp
src/Config.hpp
src/storage/primary/PrimaryStorage.cpp

index 5e239e47a93666bdb845a67d6188a5dc6ea8d398..5628e7a81bd9a2ad6af7c2db030eca5f35731328 100644 (file)
@@ -1034,7 +1034,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
@@ -1045,5 +1045,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";
 }
index fabe0e1d9361b8ac46363801920177ab733b473a..dbec498529f4e536c1b6e44a1f8878f18dfd2c44 100644 (file)
@@ -90,6 +90,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);
@@ -197,8 +199,6 @@ private:
                 const std::optional<std::string>& env_var_key,
                 bool negate,
                 const std::string& origin);
-
-  static std::string default_temporary_dir(const std::string& cache_dir);
 };
 
 inline bool
@@ -478,7 +478,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();
   }
 }
 
index b3e709bb114be5ba6f457b771b497adc99959867..8b14c4bb395850fbe38372bf7e04bc6b9d7b917d 100644 (file)
@@ -98,7 +98,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();
   }
 }