]> 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, 20 Aug 2022 11:53:50 +0000 (13:53 +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

(cherry picked from commit ce6b0c3dbdf1f84ab625d4c86770297f93b87032)

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

index ee4cd9f7f10e21ad8086c45349e27f5f6c835a24..22c5cc0e638b9f4599d8ba126e018f42fe38035b 100644 (file)
@@ -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";
 }
index 6275fa65930245cdcb8b3a092c4b90ab700a9522..a9e08eca3f23c5213dd5b6014c01388f3b4c9f93 100644 (file)
@@ -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<std::string>& 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();
   }
 }
 
index 7ba213763574004bd15b2e5835f6d1f421e53940..3584776d7838842df25cdbe6b69a1712e4a35987 100644 (file)
@@ -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();
   }
 }