From: Joel Rosdahl Date: Tue, 13 Jan 2026 20:22:30 +0000 (+0100) Subject: enhance: Add Config::get_xdg_runtime_tmp_dir X-Git-Tag: v4.13~46 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=67cd2c0f107b6b2f0213ed88cd445a13e5f4317c;p=thirdparty%2Fccache.git enhance: Add Config::get_xdg_runtime_tmp_dir --- diff --git a/src/ccache/config.cpp b/src/ccache/config.cpp index dcf7c17d..dd03e888 100644 --- a/src/ccache/config.cpp +++ b/src/ccache/config.cpp @@ -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"; } diff --git a/src/ccache/config.hpp b/src/ccache/config.hpp index 83cd77ec..6cd5d35c 100644 --- a/src/ccache/config.hpp +++ b/src/ccache/config.hpp @@ -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& value);