]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Use $XDG_RUNTIME_DIR/ccache-tmp as the default temporary directory
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 13 Nov 2022 13:43:35 +0000 (14:43 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 13 Nov 2022 15:36:30 +0000 (16:36 +0100)
See discussion in #1221.

cmake/GenerateConfigurationFile.cmake
cmake/config.h.in
doc/MANUAL.adoc
src/Config.cpp

index 20be4eac11f9efeb8114845d488e799aa65583e8..858567b94a6e8dfac90db3828588c810ba0f8c01 100644 (file)
@@ -26,7 +26,6 @@ endforeach()
 include(CheckFunctionExists)
 set(functions
     asctime_r
-    geteuid
     getopt_long
     getpwuid
     posix_fallocate
index 28ea3c2a91e14aca9e19342af6a33a0f90285f0a..1537119b84e6514a9f391bb8089ccc398e4ecba8 100644 (file)
@@ -76,9 +76,6 @@
 // Define if your compiler supports AVX2.
 #cmakedefine HAVE_AVX2
 
-// Define if you have the "geteuid" function.
-#cmakedefine HAVE_GETEUID
-
 // Define if you have the "getopt_long" function.
 #cmakedefine HAVE_GETOPT_LONG
 
index b9a202ca58958fd3ec4f57058fd4786c51af0388..48328fa8e3847cff99931de773ac52fe2a2114c4 100644 (file)
@@ -1036,7 +1036,8 @@ NOTE: Lines in the stats log starting with a hash sign (`#`) are comments.
 *temporary_dir* (*CCACHE_TEMPDIR*)::
 
     This option specifies where ccache will put temporary files. The default is
-    `/run/user/<UID>/ccache-tmp` if `/run/user/<UID>` exists, otherwise
+    `$XDG_RUNTIME_DIR/ccache-tmp` (typically `/run/user/<UID>/ccache-tmp`) if
+    `XDG_RUNTIME_DIR` is set and the directory exists, otherwise
     `<cache_dir>/tmp`.
 +
 NOTE: In previous versions of ccache, *CCACHE_TEMPDIR* had to be on the same
index 5755c1b65f0e2d557293c3a3f10c9ffb9690fdfa..75a1358d70aa3404dff2a2a4039fa9a51b59acd0 100644 (file)
@@ -1114,9 +1114,10 @@ std::string
 Config::default_temporary_dir() const
 {
   static const std::string run_user_tmp_dir = [] {
-#ifdef HAVE_GETEUID
-    if (Stat::stat("/run").is_directory()) {
-      auto dir = FMT("/run/user/{}/ccache-tmp", geteuid());
+#ifndef _WIN32
+    const char* const xdg_runtime_dir = getenv("XDG_RUNTIME_DIR");
+    if (xdg_runtime_dir && Stat::stat(xdg_runtime_dir).is_directory()) {
+      auto dir = FMT("{}/ccache-tmp", xdg_runtime_dir);
       if (Util::create_dir(dir) && access(dir.c_str(), W_OK) == 0) {
         return dir;
       }