diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2022-11-13 14:43:35 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2022-11-13 16:36:30 +0100 |
commit | 876509ae8b95f76adebdfa1f2380d75a49f9871d (patch) | |
tree | ce9c3dca6583c915eea3d8adf76af2ba6e0d6856 | |
parent | fee7808210fbf2ca1934d9d9eec948ab19cb5762 (diff) | |
download | ccache-876509ae8b95f76adebdfa1f2380d75a49f9871d.tar.gz |
fix: Use $XDG_RUNTIME_DIR/ccache-tmp as the default temporary directory
See discussion in #1221.
-rw-r--r-- | cmake/GenerateConfigurationFile.cmake | 1 | ||||
-rw-r--r-- | cmake/config.h.in | 3 | ||||
-rw-r--r-- | doc/MANUAL.adoc | 3 | ||||
-rw-r--r-- | src/Config.cpp | 7 |
4 files changed, 6 insertions, 8 deletions
diff --git a/cmake/GenerateConfigurationFile.cmake b/cmake/GenerateConfigurationFile.cmake index 20be4eac..858567b9 100644 --- a/cmake/GenerateConfigurationFile.cmake +++ b/cmake/GenerateConfigurationFile.cmake @@ -26,7 +26,6 @@ endforeach() include(CheckFunctionExists) set(functions asctime_r - geteuid getopt_long getpwuid posix_fallocate diff --git a/cmake/config.h.in b/cmake/config.h.in index 28ea3c2a..1537119b 100644 --- a/cmake/config.h.in +++ b/cmake/config.h.in @@ -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 diff --git a/doc/MANUAL.adoc b/doc/MANUAL.adoc index b9a202ca..48328fa8 100644 --- a/doc/MANUAL.adoc +++ b/doc/MANUAL.adoc @@ -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 diff --git a/src/Config.cpp b/src/Config.cpp index 5755c1b6..75a1358d 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -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; } |