set_config_path(config_dir / "ccache.conf");
}
- const std::string& cache_dir_before_config_file_was_read = cache_dir();
+ const fs::path& cache_dir_before_config_file_was_read = cache_dir();
update_from_file(config_path());
if (cache_dir().empty()) {
if (legacy_ccache_dir_exists) {
- set_cache_dir(util::pstr(legacy_ccache_dir));
+ set_cache_dir(legacy_ccache_dir);
#ifdef _WIN32
} else if (env_local_appdata) {
- set_cache_dir(util::pstr(fs::path(env_local_appdata) / "ccache"));
+ set_cache_dir(fs::path(env_local_appdata) / "ccache");
} else {
throw core::Fatal(
"could not find cache directory and the LOCALAPPDATA environment"
return util::pstr(m_base_dir);
case ConfigItem::cache_dir:
- return m_cache_dir;
+ return m_cache_dir.string();
case ConfigItem::compiler:
return m_compiler;
#endif
return std::string();
}();
- return !run_user_tmp_dir.empty() ? run_user_tmp_dir : m_cache_dir + "/tmp";
+ return !run_user_tmp_dir.empty() ? run_user_tmp_dir
+ : util::pstr(m_cache_dir / "tmp");
}
bool absolute_paths_in_stderr() const;
const std::filesystem::path& base_dir() const;
- const std::string& cache_dir() const;
+ const std::filesystem::path& cache_dir() const;
const std::string& compiler() const;
const std::string& compiler_check() const;
CompilerType compiler_type() const;
std::string default_temporary_dir() const;
void set_base_dir(const std::filesystem::path& value);
- void set_cache_dir(const std::string& value);
+ void set_cache_dir(const std::filesystem::path& value);
void set_compiler(const std::string& value);
void set_compiler_type(CompilerType value);
void set_cpp_extension(const std::string& value);
bool m_absolute_paths_in_stderr = false;
std::filesystem::path m_base_dir;
- std::string m_cache_dir;
+ std::filesystem::path m_cache_dir;
std::string m_compiler;
std::string m_compiler_check = "mtime";
CompilerType m_compiler_type = CompilerType::auto_guess;
return m_base_dir;
}
-inline const std::string&
+inline const std::filesystem::path&
Config::cache_dir() const
{
return m_cache_dir;
}
inline void
-Config::set_cache_dir(const std::string& value)
+Config::set_cache_dir(const std::filesystem::path& value)
{
m_cache_dir = value;
if (!m_temporary_dir_configured_explicitly) {
};
if (verbosity > 0 && !from_log) {
- table.add_row({"Cache directory:", C(config.cache_dir()).colspan(4)});
+ table.add_row(
+ {"Cache directory:", C(util::pstr(config.cache_dir())).colspan(4)});
table.add_row(
{"Config file:", C(util::pstr(config.config_path())).colspan(4)});
table.add_row({"System config file:",
const auto zeroable_fields = core::Statistics::get_zeroable_fields();
for_each_level_1_and_2_stats_file(
- m_config.cache_dir(), [=](const std::string& path) {
+ util::pstr(m_config.cache_dir()), [=](const std::string& path) {
StatsFile(path).update([=](auto& cs) {
for (const auto statistic : zeroable_fields) {
cs.set(statistic, 0);
// Add up the stats in each directory.
for_each_level_1_and_2_stats_file(
- m_config.cache_dir(), [&](const auto& path) {
+ util::pstr(m_config.cache_dir()), [&](const auto& path) {
counters.set(Statistic::stats_zeroed_timestamp, 0); // Don't add
counters.increment(StatsFile(path).read());
zero_timestamp = std::max(counters.get(Statistic::stats_zeroed_timestamp),
ASSERT(level >= 1 && level <= 8);
ASSERT(name.length() >= level);
- std::string path(m_config.cache_dir());
- path.reserve(path.size() + level * 2 + 1 + name.length() - level);
-
+ fs::path path(m_config.cache_dir());
for (uint8_t i = 0; i < level; ++i) {
- path.push_back('/');
- path.push_back(name.at(i));
+ path /= std::string(1, name.at(i));
}
- path.push_back('/');
- const std::string_view name_remaining = name.substr(level);
- path.append(name_remaining.data(), name_remaining.length());
-
- return path;
+ return (path / fs::path(name.substr(level))).string();
}
std::string