]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
enhance: Add Config::get_xdg_runtime_tmp_dir
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 13 Jan 2026 20:22:30 +0000 (21:22 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 13 Jan 2026 20:39:38 +0000 (21:39 +0100)
src/ccache/config.cpp
src/ccache/config.hpp

index dcf7c17d71b9cc616c7ec4b078cd388445705ff5..dd03e88866a56b30d61281324c10d7ac95844f43 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2025 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2026 Joel Rosdahl and other contributors
 //
 // See doc/authors.adoc for a complete list of contributors.
 //
@@ -1244,17 +1244,23 @@ Config::check_key_tables_consistency()
 fs::path
 Config::default_temporary_dir() const
 {
-  static const fs::path run_user_tmp_dir = [] {
-#ifndef _WIN32
-    const char* const xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
-    if (xdg_runtime_dir && DirEntry(xdg_runtime_dir).is_directory()) {
-      fs::path dir = FMT("{}/ccache-tmp", xdg_runtime_dir);
-      if (fs::create_directories(dir) && access(dir.c_str(), W_OK) == 0) {
-        return dir;
-      }
+  const auto dir = get_xdg_runtime_tmp_dir();
+  return !dir.empty() ? dir : m_cache_dir / "tmp";
+}
+
+std::filesystem::path
+Config::get_xdg_runtime_tmp_dir()
+{
+#ifdef _WIN32
+  return {};
+#else
+  const char* const xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
+  if (xdg_runtime_dir && DirEntry(xdg_runtime_dir).is_directory()) {
+    fs::path dir = FMT("{}/ccache-tmp", xdg_runtime_dir);
+    if (fs::create_directories(dir) && access(dir.c_str(), W_OK) == 0) {
+      return dir;
     }
+  }
+  return {};
 #endif
-    return fs::path();
-  }();
-  return !run_user_tmp_dir.empty() ? run_user_tmp_dir : m_cache_dir / "tmp";
 }
index 83cd77ecef76f777a8b6b930ae74da287ba66929..6cd5d35cf206a648aca4dbb417531834be946126 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2025 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2026 Joel Rosdahl and other contributors
 //
 // See doc/authors.adoc for a complete list of contributors.
 //
@@ -110,6 +110,7 @@ public:
 
   util::SizeUnitPrefixType size_unit_prefix_type() const;
   std::filesystem::path default_temporary_dir() const;
+  static std::filesystem::path get_xdg_runtime_tmp_dir();
 
   void set_base_dir(const std::filesystem::path& value);
   void set_base_dirs(const std::vector<std::filesystem::path>& value);