From: Joel Rosdahl Date: Thu, 6 Jan 2022 15:57:00 +0000 (+0100) Subject: fix: Check writability of /run/user//ccache-tmp before using X-Git-Tag: v4.6~51 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a0edd4294f6a5a2d3f0c7b01273736f975f250e1;p=thirdparty%2Fccache.git fix: Check writability of /run/user//ccache-tmp before using Closes #984. --- diff --git a/src/Config.cpp b/src/Config.cpp index bea38d920..0a3ccca4a 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2019-2021 Joel Rosdahl and other contributors +// Copyright (C) 2019-2022 Joel Rosdahl and other contributors // // See doc/AUTHORS.adoc for a complete list of contributors. // @@ -1025,11 +1025,14 @@ Config::check_key_tables_consistency() std::string Config::default_temporary_dir(const std::string& cache_dir) { + static const std::string run_user_tmp_dir = [] { #ifdef HAVE_GETEUID - std::string user_tmp_dir = FMT("/run/user/{}", geteuid()); - if (Stat::stat(user_tmp_dir).is_directory()) { - return user_tmp_dir + "/ccache-tmp"; - } + const auto dir = FMT("/run/user/{}/ccache-tmp", geteuid()); + if (Util::create_dir(dir)) { + return dir; + } #endif - return cache_dir + "/tmp"; + return std::string(); + }(); + return !run_user_tmp_dir.empty() ? run_user_tmp_dir : cache_dir + "/tmp"; }