#include <ccache/core/common.hpp>
#include <ccache/core/exceptions.hpp>
#include <ccache/util/DirEntry.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/Tokenizer.hpp>
#include <ccache/util/UmaskScope.hpp>
#include <ccache/util/assertions.hpp>
namespace fs = util::filesystem;
-using pstr = util::PathString;
using util::DirEntry;
using util::make_path;
if (cache_dir().empty()) {
if (legacy_ccache_dir_exists) {
- set_cache_dir(pstr(legacy_ccache_dir));
+ set_cache_dir(util::pstr(legacy_ccache_dir));
#ifdef _WIN32
} else if (env_local_appdata) {
- set_cache_dir(pstr(fs::path(env_local_appdata) / "ccache"));
+ set_cache_dir(util::pstr(fs::path(env_local_appdata) / "ccache"));
} else {
throw core::Fatal(
"could not find cache directory and the LOCALAPPDATA environment"
Config::update_from_file(const fs::path& path)
{
return parse_config_file(
- pstr(path), [&](const auto& /*line*/, const auto& key, const auto& value) {
+ util::pstr(path),
+ [&](const auto& /*line*/, const auto& key, const auto& value) {
if (!key.empty()) {
- set_item(key, value, std::nullopt, false, pstr(path));
+ set_item(key, value, std::nullopt, false, util::pstr(path));
}
});
}
return format_bool(m_absolute_paths_in_stderr);
case ConfigItem::base_dir:
- return pstr(m_base_dir).str();
+ return util::pstr(m_base_dir);
case ConfigItem::cache_dir:
return m_cache_dir;
#include <ccache/Hash.hpp>
#include <ccache/core/common.hpp>
#include <ccache/core/exceptions.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/Tokenizer.hpp>
#include <ccache/util/assertions.hpp>
#include <ccache/util/file.hpp>
namespace fs = util::filesystem;
-using pstr = util::PathString;
-
namespace Depfile {
std::string
auto rel_path = core::make_relative_path(ctx, token);
if (rel_path != token) {
rewritten = true;
- token = pstr(rel_path).str();
+ token = util::pstr(rel_path);
}
}
#pragma once
-#include <ccache/util/PathString.hpp>
#include <ccache/util/conversion.hpp>
+#include <ccache/util/path.hpp>
#include <blake3.h>
#include <nonstd/span.hpp>
inline Hash&
Hash::hash(const std::filesystem::path& path)
{
- hash(util::PathString(path).str());
+ hash(util::pstr(path));
return *this;
}
#include <ccache/util/DirEntry.hpp>
#include <ccache/util/Fd.hpp>
#include <ccache/util/Finalizer.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/TemporaryFile.hpp>
#include <ccache/util/conversion.hpp>
#include <ccache/util/file.hpp>
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
#include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
#include <fcntl.h>
namespace fs = util::filesystem;
-using pstr = util::PathString;
-
// The inode cache resides on a file that is mapped into shared memory by
// running processes. It is implemented as a two level structure, where the top
// level is a hash table consisting of buckets. Each bucket contains entries
return false;
}
- util::Finalizer temp_file_remover([&] { unlink(pstr(tmp_file->path)); });
+ util::Finalizer temp_file_remover(
+ [&] { unlink(util::pstr(tmp_file->path).c_str()); });
if (!fd_is_on_known_to_work_file_system(*tmp_file->fd)) {
return false;
#include <ccache/core/common.hpp>
#include <ccache/language.hpp>
#include <ccache/util/DirEntry.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/Tokenizer.hpp>
#include <ccache/util/assertions.hpp>
#include <ccache/util/filesystem.hpp>
using core::Statistic;
using util::DirEntry;
-using pstr = util::PathString;
namespace {
fs::path file = fs::path(arg).replace_extension(".pch");
if (fs::is_regular_file(file)) {
LOG("Detected use of precompiled header: {}", file);
- pch_file = pstr(file).str();
+ pch_file = util::pstr(file);
}
}
} else if (option == "-Fp") {
new_profile_path = ".";
} else {
// GCC uses $PWD/$(basename $obj).
- new_profile_path = pstr(ctx.apparent_cwd).str();
+ new_profile_path = util::pstr(ctx.apparent_cwd);
}
} else if (util::starts_with(arg, "-fprofile-generate=")
|| util::starts_with(arg, "-fprofile-instr-generate=")) {
if (state.output_dep_origin <= OutputDepOrigin::mf) {
state.output_dep_origin = OutputDepOrigin::mf;
args_info.output_dep =
- pstr(core::make_relative_path(ctx, dep_file)).str();
+ util::pstr(core::make_relative_path(ctx, dep_file));
}
// Keep the format of the args the same.
if (separate_argument) {
}
state.common_args.push_back(args[i]);
auto relpath = core::make_relative_path(ctx, args[i + 1]);
- state.common_args.push_back(pstr(relpath).str());
+ state.common_args.push_back(util::pstr(relpath));
i++;
return Statistic::none;
}
}
args_info.generating_diagnostics = true;
args_info.output_dia =
- pstr(core::make_relative_path(ctx, args[i + 1])).str();
+ util::pstr(core::make_relative_path(ctx, args[i + 1]));
i++;
return Statistic::none;
}
if (next == 2) {
dest_args.push_back(args[i + 1]);
}
- dest_args.push_back(pstr(relpath).str());
+ dest_args.push_back(util::pstr(relpath));
i += next;
return Statistic::none;
if (is_link) {
LOG_RAW("Called for link");
return tl::unexpected(
- pstr(state.input_files.front()).str().find("conftest.")
+ util::pstr(state.input_files.front()).str().find("conftest.")
!= std::string::npos
? Statistic::autoconf_test
: Statistic::called_for_link);
}
}
- args_info.orig_input_file = pstr(state.input_files.front()).str();
+ args_info.orig_input_file = util::pstr(state.input_files.front());
// Rewrite to relative to increase hit rate.
args_info.input_file =
- pstr(core::make_relative_path(ctx, args_info.orig_input_file)).str();
+ util::pstr(core::make_relative_path(ctx, args_info.orig_input_file));
// Bail out on too hard combinations of options.
if (state.found_mf_opt && state.found_wp_md_or_mmd_opt) {
} else {
extension = get_default_object_file_extension(ctx.config);
}
- args_info.output_obj +=
- pstr(
- fs::path(args_info.input_file).filename().replace_extension(extension))
- .str();
+ args_info.output_obj += util::pstr(
+ fs::path(args_info.input_file).filename().replace_extension(extension));
}
args_info.orig_output_obj = args_info.output_obj;
args_info.output_obj =
- pstr(core::make_relative_path(ctx, args_info.output_obj)).str();
+ util::pstr(core::make_relative_path(ctx, args_info.output_obj));
// Determine a filepath for precompiled header.
if (ctx.config.is_compiler_group_msvc() && args_info.generating_pch) {
}
if (included_pch_file_by_source && !args_info.input_file.empty()) {
- args_info.included_pch_file =
- pstr(fs::path(args_info.input_file)
- .filename()
- .replace_extension(get_default_pch_file_extension(ctx.config)))
- .str();
+ args_info.included_pch_file = util::pstr(
+ fs::path(args_info.input_file)
+ .filename()
+ .replace_extension(get_default_pch_file_extension(ctx.config)));
LOG(
"Setting PCH filepath from the base source file (during generating): "
"{}",
}
if (args_info.profile_path.empty()) {
- args_info.profile_path = pstr(ctx.apparent_cwd).str();
+ args_info.profile_path = util::pstr(ctx.apparent_cwd);
}
if (!state.explicit_language.empty() && state.explicit_language == "none") {
args_info.orig_output_obj =
args_info.orig_input_file + get_default_pch_file_extension(config);
args_info.output_obj =
- pstr(core::make_relative_path(ctx, args_info.orig_output_obj)).str();
+ util::pstr(core::make_relative_path(ctx, args_info.orig_output_obj));
}
if (args_info.output_is_precompiled_header
args_info.seen_split_dwarf = false;
} else {
args_info.output_dwo =
- pstr(fs::path(args_info.output_obj).replace_extension(".dwo")).str();
+ util::pstr(fs::path(args_info.output_obj).replace_extension(".dwo"));
}
}
if (args_info.generating_dependencies) {
if (state.output_dep_origin == OutputDepOrigin::none) {
args_info.output_dep =
- pstr(fs::path(args_info.output_obj).replace_extension(".d")).str();
+ util::pstr(fs::path(args_info.output_obj).replace_extension(".d"));
if (!config.run_second_cpp()) {
// If we're compiling preprocessed code we're sending dep_args to the
// preprocessor so we need to use -MF to write to the correct .d file
std::string default_sufile_name =
fs::path(args_info.output_obj).replace_extension(".su").string();
args_info.output_su =
- pstr(core::make_relative_path(ctx, default_sufile_name)).str();
+ util::pstr(core::make_relative_path(ctx, default_sufile_name));
}
if (args_info.generating_callgraphinfo) {
std::string default_cifile_name =
fs::path(args_info.output_obj).replace_extension(".ci").string();
args_info.output_ci =
- pstr(core::make_relative_path(ctx, default_cifile_name)).str();
+ util::pstr(core::make_relative_path(ctx, default_cifile_name));
}
if (args_info.generating_ipa_clones) {
fs::path ipa_path(args_info.orig_input_file + ".000i.ipa-clones");
- args_info.output_ipa = pstr(core::make_relative_path(ctx, ipa_path)).str();
+ args_info.output_ipa = util::pstr(core::make_relative_path(ctx, ipa_path));
}
Args compiler_args = state.common_args;
#include <ccache/util/Fd.hpp>
#include <ccache/util/FileStream.hpp>
#include <ccache/util/Finalizer.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/TemporaryFile.hpp>
#include <ccache/util/TimePoint.hpp>
#include <ccache/util/Tokenizer.hpp>
using core::Statistic;
using util::DirEntry;
-using pstr = util::PathString;
// This is a string that identifies the current "version" of the hash sum
// computed by ccache. If, for any reason, we want to force the hash sum to be
} // namespace
static bool
-should_disable_ccache_for_input_file(const std::string& path)
+should_disable_ccache_for_input_file(const fs::path& path)
{
auto content =
util::read_file_part<std::string>(path, 0, k_ccache_disable_search_limit);
static_cast<long long unsigned int>(time_of_invocation.sec()));
}
return FMT("{}.{}_{:06}.ccache-{}",
- pstr(prefix).str(),
+ prefix,
timestamp,
time_of_invocation.nsec_decimal_part() / 1000,
suffix);
do_guess_compiler(const fs::path& path)
{
const auto name =
- util::to_lowercase(pstr(path.filename().replace_extension("")).str());
+ util::to_lowercase(util::pstr(path.filename().replace_extension("")).str());
if (name.find("clang-cl") != std::string_view::npos) {
return CompilerType::clang_cl;
} else if (name.find("clang") != std::string_view::npos) {
auto it = relative_inc_path_cache.find(inc_path);
if (it == relative_inc_path_cache.end()) {
std::string rel_inc_path =
- pstr(core::make_relative_path(ctx, inc_path)).str();
+ util::pstr(core::make_relative_path(ctx, inc_path));
relative_inc_path_cache.emplace(inc_path, rel_inc_path);
- inc_path = pstr(rel_inc_path).str();
+ inc_path = util::pstr(rel_inc_path);
} else {
inc_path = it->second;
}
// mention of it in the preprocessed output.
if (!ctx.args_info.included_pch_file.empty()
&& !ctx.args_info.generating_pch) {
- std::string pch_path =
- pstr(core::make_relative_path(ctx, ctx.args_info.included_pch_file));
+ std::string pch_path = util::pstr(
+ core::make_relative_path(ctx, ctx.args_info.included_pch_file));
hash.hash(pch_path);
TRY(remember_include_file(ctx, pch_path, hash, false, nullptr));
}
}
if (seen_colon) {
fs::path path = core::make_relative_path(ctx, token);
- TRY(remember_include_file(ctx, pstr(path), hash, false, &hash));
+ TRY(remember_include_file(ctx, util::pstr(path), hash, false, &hash));
} else if (token == ":") {
seen_colon = true;
}
fs::path pch_path =
core::make_relative_path(ctx, ctx.args_info.included_pch_file);
hash.hash(pch_path);
- TRY(remember_include_file(ctx, pstr(pch_path), hash, false, nullptr));
+ TRY(remember_include_file(ctx, util::pstr(pch_path), hash, false, nullptr));
}
bool debug_included = getenv("CCACHE_DEBUG_INCLUDED");
auto tmp_stdout =
util::value_or_throw<core::Fatal>(util::TemporaryFile::create(
FMT("{}/{}", ctx.config.temporary_dir(), description)));
- ctx.register_pending_tmp_file(pstr(tmp_stdout.path));
+ ctx.register_pending_tmp_file(util::pstr(tmp_stdout.path));
return {std::move(tmp_stdout.fd), std::move(tmp_stdout.path)};
} else {
const auto dev_null_path = util::get_dev_null_path();
for (std::string_view include : core::MsvcShowIncludesOutput::get_includes(
stdout_data, ctx.config.msvc_dep_prefix())) {
const fs::path path = core::make_relative_path(ctx, include);
- TRY(remember_include_file(ctx, pstr(path), hash, false, &hash));
+ TRY(remember_include_file(ctx, util::pstr(path), hash, false, &hash));
}
// Explicitly check the .pch file as it is not mentioned in the
fs::path pch_path =
core::make_relative_path(ctx, ctx.args_info.included_pch_file);
hash.hash(pch_path);
- TRY(remember_include_file(ctx, pstr(pch_path), hash, false, nullptr));
+ TRY(remember_include_file(ctx, util::pstr(pch_path), hash, false, nullptr));
}
const bool debug_included = getenv("CCACHE_DEBUG_INCLUDED");
abs_inc_path = util::strip_whitespace(abs_inc_path);
fs::path rel_inc_path = core::make_relative_path(ctx, abs_inc_path);
std::string line_with_rel_inc = util::replace_first(
- orig_line, abs_inc_path, pstr(rel_inc_path).str());
+ orig_line, abs_inc_path, util::pstr(rel_inc_path).str());
new_stdout_data.insert(new_stdout_data.end(),
line_with_rel_inc.data(),
line_with_rel_inc.size());
// Possibly hash the current working directory.
if (args_info.generating_debuginfo && ctx.config.hash_dir()) {
- std::string dir_to_hash = pstr(ctx.apparent_cwd).str();
+ std::string dir_to_hash = util::pstr(ctx.apparent_cwd);
for (const auto& map : args_info.debug_prefix_maps) {
size_t sep_pos = map.find('=');
if (sep_pos != std::string::npos) {
old_path,
new_path,
ctx.apparent_cwd);
- if (util::starts_with(pstr(ctx.apparent_cwd), old_path)) {
+ if (util::starts_with(util::pstr(ctx.apparent_cwd).str(), old_path)) {
dir_to_hash =
- new_path + pstr(ctx.apparent_cwd).str().substr(old_path.size());
+ new_path
+ + util::pstr(ctx.apparent_cwd).str().substr(old_path.size());
}
}
}
const std::string output_obj_dir =
fs::path(args_info.output_obj).is_absolute()
? fs::path(args_info.output_obj).parent_path().string()
- : pstr(ctx.actual_cwd);
+ : util::pstr(ctx.actual_cwd);
LOG("Hashing object file directory {}", output_obj_dir);
hash.hash_delimiter("source path");
hash.hash(output_obj_dir);
// base name would be enough.
LOG_RAW("Hashing object filename due to -gsplit-dwarf");
hash.hash_delimiter("object file");
- hash.hash(pstr(fs::path(ctx.args_info.output_obj).filename()).str());
+ hash.hash(util::pstr(fs::path(ctx.args_info.output_obj).filename()));
}
if (ctx.args_info.profile_arcs) {
{
const std::string& profile_path = ctx.args_info.profile_path;
const std::string base_name =
- pstr(fs::path(ctx.args_info.output_obj).replace_extension("")).str();
- std::string hashified_cwd = pstr(ctx.apparent_cwd).str();
+ util::pstr(fs::path(ctx.args_info.output_obj).replace_extension(""));
+ std::string hashified_cwd = util::pstr(ctx.apparent_cwd);
std::replace(hashified_cwd.begin(), hashified_cwd.end(), '/', '#');
std::vector<std::string> paths_to_try{
if (argc < 2) {
PRINT_RAW(
stderr,
- core::get_usage_text(pstr(fs::path(argv[0]).filename()).str()));
+ core::get_usage_text(util::pstr(fs::path(argv[0]).filename()).str()));
exit(EXIT_FAILURE);
}
// If the first argument isn't an option, then assume we are being
#include "Statistics.hpp"
#include <ccache/Config.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/TextTable.hpp>
#include <ccache/util/format.hpp>
#include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
#include <ccache/util/string.hpp>
#include <ccache/util/time.hpp>
namespace core {
-using pstr = util::PathString;
using core::Statistic;
const unsigned FLAG_NOZERO = 1U << 0; // don't zero with --zero-stats
if (verbosity > 0 && !from_log) {
table.add_row({"Cache directory:", C(config.cache_dir()).colspan(4)});
table.add_row(
- {"Config file:", C(pstr(config.config_path()).str()).colspan(4)});
+ {"Config file:", C(util::pstr(config.config_path())).colspan(4)});
table.add_row({"System config file:",
- C(pstr(config.system_config_path()).str()).colspan(4)});
+ C(util::pstr(config.system_config_path())).colspan(4)});
table.add_row(
{"Stats updated:", C(format_timestamp(last_updated)).colspan(4)});
if (verbosity > 1) {
#include <ccache/core/Statistics.hpp>
#include <ccache/util/FileStream.hpp>
+#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
#include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
#include <cstring>
#include <fstream>
+namespace fs = util::filesystem;
+
namespace core {
StatisticsCounters
}
void
-StatsLog::log_result(const std::string& input_file,
+StatsLog::log_result(const fs::path& input_file,
const std::vector<std::string>& result_ids)
{
util::FileStream file(m_path, "ab");
-// Copyright (C) 2021-2023 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2024 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "StatisticsCounters.hpp"
+#include <filesystem>
#include <string>
#include <vector>
class StatsLog
{
public:
- explicit StatsLog(const std::string& path);
+ explicit StatsLog(const std::filesystem::path& path);
StatisticsCounters read() const;
- void log_result(const std::string& input_file,
+ void log_result(const std::filesystem::path& input_file,
const std::vector<std::string>& result_ids);
private:
- const std::string m_path;
+ std::filesystem::path m_path;
};
// --- Inline implementations ---
-inline StatsLog::StatsLog(const std::string& path) : m_path(path)
+inline StatsLog::StatsLog(const std::filesystem::path& path) : m_path(path)
{
}
#include <ccache/Context.hpp>
#include <ccache/core/exceptions.hpp>
#include <ccache/util/Finalizer.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/Tokenizer.hpp>
#include <ccache/util/expected.hpp>
#include <ccache/util/file.hpp>
#include <ccache/util/path.hpp>
using IncludeDelimiter = util::Tokenizer::IncludeDelimiter;
-using pstr = util::PathString;
namespace fs = util::filesystem;
result.append(line.data(), line.length());
} else {
fs::path path(line.substr(0, path_end));
- result += pstr(fs::canonical(path).value_or(path)).str();
+ result += util::pstr(fs::canonical(path).value_or(path));
auto tail = line.substr(path_end);
result.append(tail.data(), tail.length());
}
#include <ccache/storage/local/LocalStorage.hpp>
#include <ccache/util/Fd.hpp>
#include <ccache/util/FileStream.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/TemporaryFile.hpp>
#include <ccache/util/TextTable.hpp>
#include <ccache/util/ThreadPool.hpp>
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
#include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
#include <ccache/util/string.hpp>
#include <fcntl.h>
namespace fs = util::filesystem;
using util::DirEntry;
-using pstr = util::PathString;
namespace core {
case 'F': { // --max-files
auto files = util::value_or_throw<Error>(util::parse_unsigned(arg));
config.set_value_in_file(
- pstr(config.config_path()).str(), "max_files", arg);
+ util::pstr(config.config_path()), "max_files", arg);
if (files == 0) {
PRINT_RAW(stdout, "Unset cache file limit\n");
} else {
util::value_or_throw<Error>(util::parse_size(arg));
uint64_t max_size = size;
config.set_value_in_file(
- pstr(config.config_path()).str(), "max_size", arg);
+ util::pstr(config.config_path()), "max_size", arg);
if (max_size == 0) {
PRINT_RAW(stdout, "Unset cache size limit\n");
} else {
}
std::string key = arg.substr(0, eq_pos);
std::string value = arg.substr(eq_pos + 1);
- config.set_value_in_file(pstr(config.config_path()).str(), key, value);
+ config.set_value_in_file(util::pstr(config.config_path()), key, value);
break;
}
case 'V': // --version
{
- PRINT_RAW(stdout, get_version_text(pstr(fs::path(argv[0]).stem()).str()));
+ PRINT_RAW(stdout,
+ get_version_text(util::pstr(fs::path(argv[0]).stem()).str()));
break;
}
#include <ccache/util/DirEntry.hpp>
#include <ccache/util/Fd.hpp>
#include <ccache/util/Finalizer.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/TemporaryFile.hpp>
#include <ccache/util/error.hpp>
#include <ccache/util/expected.hpp>
namespace fs = util::filesystem;
-using pstr = util::PathString;
-
#ifdef _WIN32
static int win32execute(const char* path,
const char* const* argv,
{
const char* path_list = getenv("PATH");
std::string sh;
- if (util::to_lowercase(pstr(fs::path(path).extension()).str()) == ".sh"
+ if (util::to_lowercase(util::pstr(fs::path(path).extension()).str()) == ".sh"
&& path_list) {
- sh = pstr(find_executable_in_path("sh.exe", path_list)).str();
+ sh = util::pstr(find_executable_in_path("sh.exe", path_list));
}
if (sh.empty() && getenv("CCACHE_DETECT_SHEBANG")) {
// Detect shebang.
char buf[10] = {0};
fgets(buf, sizeof(buf) - 1, fp.get());
if (std::string(buf) == "#!/bin/sh" && path_list) {
- sh = pstr(find_executable_in_path("sh.exe", path_list)).str();
+ sh = util::pstr(find_executable_in_path("sh.exe", path_list));
}
}
}
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
#include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
#include <ccache/util/process.hpp>
#include <ccache/util/string.hpp>
#include <ccache/util/wincompat.hpp>
using core::StatisticsCounters;
using util::DirEntry;
-using pstr = util::PathString;
-
namespace storage::local {
// How often (in seconds) to scan $CCACHE_DIR/tmp for left-over temporary
}
if (namespace_ && file_type_from_path(file.path()) == FileType::raw) {
- auto path_str = pstr(file.path());
+ util::PathString path_str(file.path());
const auto result_filename =
FMT("{}R", path_str.str().substr(0, path_str.str().length() - 2));
- raw_files_map[result_filename].push_back(pstr(file.path()).str());
+ raw_files_map[result_filename].push_back(util::pstr(file.path()));
}
cache_size += file.size_on_disk();
// For namespace eviction we need to remove raw files based on result
// filename since they don't have a header.
if (file_type_from_path(file.path()) == FileType::result) {
- const auto entry = raw_files_map.find(pstr(file.path()));
+ const auto entry = raw_files_map.find(util::pstr(file.path()));
if (entry != raw_files_map.end()) {
for (const auto& raw_file : entry->second) {
delete_file(DirEntry(raw_file), cache_size, files_in_cache);
FileType
file_type_from_path(const fs::path& path)
{
- std::string filename = pstr(path.filename()).str();
+ std::string filename = util::pstr(path.filename());
if (util::ends_with(filename, "M")) {
return FileType::manifest;
} else if (util::ends_with(filename, "R")) {
#include "util.hpp"
#include <ccache/core/exceptions.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/expected.hpp>
#include <ccache/util/file.hpp>
#include <ccache/util/format.hpp>
+#include <ccache/util/path.hpp>
#include <ccache/util/string.hpp>
using util::DirEntry;
-using pstr = util::PathString;
namespace storage::local {
}
util::throw_on_error<core::Error>(
util::traverse_directory(dir, [&](const auto& de) {
- std::string name = pstr(de.path().filename()).str();
+ std::string name = util::pstr(de.path().filename());
if (name == "CACHEDIR.TAG" || name == "stats"
|| util::starts_with(name, ".nfs")) {
return;
#include <cstring>
-using pstr = util::PathString;
-
namespace {
#ifdef _WIN32
} else
#endif
{
- auto mpath = pstr(m_path);
- result = lstat_func(mpath, &m_stat);
+ util::PathString mpath(m_path);
+ result = lstat_func(mpath.c_str(), &m_stat);
if (result == 0) {
if (S_ISLNK(m_stat.st_mode)
#ifdef _WIN32
) {
m_is_symlink = true;
stat_t st;
- if (stat_func(mpath, &st) == 0) {
+ if (stat_func(mpath.c_str(), &st) == 0) {
m_stat = st;
m_exists = true;
}
#pragma once
#include <ccache/util/NonCopyable.hpp>
+#include <ccache/util/path.hpp>
#include <cstdio>
-#include <string>
namespace util {
public:
FileStream() = default;
explicit FileStream(FILE* file);
- FileStream(const std::string& path, const char* mode);
+ FileStream(const std::filesystem::path& path, const char* mode);
FileStream(FileStream&& other) noexcept;
~FileStream();
FileStream& operator=(FileStream&& other) noexcept;
- void open(const std::string& path, const char* mode);
+ void open(const std::filesystem::path& path, const char* mode);
void close();
operator bool() const;
{
}
-inline FileStream::FileStream(const std::string& path, const char* mode)
+inline FileStream::FileStream(const std::filesystem::path& path,
+ const char* mode)
{
open(path, mode);
}
}
inline void
-FileStream::open(const std::string& path, const char* mode)
+FileStream::open(const std::filesystem::path& path, const char* mode)
{
close();
- m_file = fopen(path.c_str(), mode);
+ m_file = fopen(util::pstr(path).c_str(), mode);
m_owned = true;
}
#include "LockFile.hpp"
#include <ccache/util/DirEntry.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/assertions.hpp>
#include <ccache/util/error.hpp>
#include <ccache/util/file.hpp>
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
#include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
#include <ccache/util/process.hpp>
#include <ccache/util/wincompat.hpp>
namespace fs = util::filesystem;
-using pstr = util::PathString;
-
namespace {
class RandomNumberGenerator
namespace util {
LockFile::LockFile(const fs::path& path)
- : m_lock_file(pstr(path).str() + ".lock"),
+ : m_lock_file(util::pstr(path).str() + ".lock"),
#ifndef _WIN32
- m_alive_file(pstr(path).str() + ".alive"),
+ m_alive_file(util::pstr(path).str() + ".alive"),
m_acquired(false)
#else
m_handle(INVALID_HANDLE_VALUE)
while (true) {
DWORD flags = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_DELETE_ON_CLOSE;
- handle = CreateFile(pstr(m_lock_file),
+ handle = CreateFile(util::pstr(m_lock_file).c_str(),
GENERIC_WRITE, // desired access
0, // shared mode (0 = not shared)
nullptr, // security attributes
PathString(const std::filesystem::path& path);
operator const std::string&() const;
- operator const char*() const;
const std::string& str() const;
const char* c_str() const;
return str();
}
-inline PathString::operator const char*() const
-{
- return c_str();
-}
-
inline const std::string&
PathString::str() const
{
#include "TemporaryFile.hpp"
-#include <ccache/util/PathString.hpp>
#include <ccache/util/file.hpp>
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
+#include <ccache/util/path.hpp>
#include <ccache/util/process.hpp>
#include <cstdlib>
namespace fs = util::filesystem;
-using pstr = util::PathString;
-
namespace util {
TemporaryFile::TemporaryFile(Fd&& fd_, const fs::path& path_)
bool
TemporaryFile::is_tmp_file(const fs::path& path)
{
- return pstr(path.filename()).str().find(tmp_file_infix) != std::string::npos;
+ return util::pstr(path.filename()).str().find(tmp_file_infix)
+ != std::string::npos;
}
} // namespace util
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
#include <ccache/util/logging.hpp>
+#include <ccache/util/path.hpp>
#ifdef __APPLE__
# include <copyfile.h>
namespace fs = util::filesystem;
-using pstr = util::PathString;
-
namespace util {
#ifdef _WIN32
tmp_file = std::move(temp_file->path);
dst_cstr = tmp_file.c_str();
}
- unlink(pstr(dest));
+ unlink(util::pstr(dest).c_str());
if (!CopyFileExW(src.c_str(), dst_cstr, nullptr, nullptr, nullptr, 0)) {
return tl::unexpected(
FMT("Failed to copy {} to {}: {}", src, dest, strerror(errno)));
ViaTmpFile via_tmp_file,
fs::path& tmp_file)
{
- Fd src_fd(open(pstr(src), O_RDONLY | O_BINARY));
+ Fd src_fd(open(util::pstr(src).c_str(), O_RDONLY | O_BINARY));
if (!src_fd) {
return tl::unexpected(
FMT("Failed to open {} for reading: {}", src, strerror(errno)));
}
- unlink(pstr(dest));
+ unlink(util::pstr(dest).c_str());
Fd dst_fd;
if (via_tmp_file == ViaTmpFile::yes) {
dst_fd = std::move(temp_file->fd);
tmp_file = std::move(temp_file->path);
} else {
- dst_fd =
- Fd(open(pstr(dest), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
+ dst_fd = Fd(open(
+ util::pstr(dest).c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
if (!dst_fd) {
return tl::unexpected(
FMT("Failed to open {} for writing: {}", dest, strerror(errno)));
return O_RDONLY | O_BINARY;
}
}();
- Fd fd(open(pstr(path), open_flags));
+ Fd fd(open(util::pstr(path).c_str(), open_flags));
if (!fd) {
return tl::unexpected(strerror(errno));
}
return result;
}
- Fd fd(open(pstr(path), O_RDONLY | O_BINARY));
+ Fd fd(open(util::pstr(path).c_str(), O_RDONLY | O_BINARY));
if (!fd) {
LOG("Failed to open {}: {}", path, strerror(errno));
return tl::unexpected(strerror(errno));
atime_mtime[0] = (atime ? *atime : *mtime).to_timespec();
atime_mtime[1] = mtime->to_timespec();
}
- utimensat(AT_FDCWD, pstr(path), mtime ? atime_mtime : nullptr, 0);
+ utimensat(
+ AT_FDCWD, util::pstr(path).c_str(), mtime ? atime_mtime : nullptr, 0);
#elif defined(HAVE_UTIMES)
timeval atime_mtime[2];
if (mtime) {
atime_mtime[1].tv_sec = mtime->sec();
atime_mtime[1].tv_usec = mtime->nsec_decimal_part() / 1000;
}
- utimes(pstr(path), mtime ? atime_mtime : nullptr);
+ utimes(util::pstr(path).c_str(), mtime ? atime_mtime : nullptr);
#else
utimbuf atime_mtime;
if (mtime) {
atime_mtime.actime = atime ? atime->sec() : mtime->sec();
atime_mtime.modtime = mtime->sec();
- utime(pstr(path), &atime_mtime);
+ utime(util::pstr(path).c_str(), &atime_mtime);
} else {
- utime(pstr(path), nullptr);
+ utime(util::pstr(path).c_str(), nullptr);
}
#endif
}
traverse_directory(const fs::path& directory,
const TraverseDirectoryVisitor& visitor)
{
- DIR* dir = opendir(pstr(directory));
+ DIR* dir = opendir(util::pstr(directory).c_str());
if (!dir) {
return tl::unexpected(
FMT("Failed to traverse {}: {}", directory, strerror(errno)));
tl::expected<void, std::string>
write_file(const fs::path& path, std::string_view data, WriteFileMode mode)
{
- auto path_str = pstr(path);
+ util::PathString path_str(path);
if (mode == WriteFileMode::unlink) {
- unlink(path_str);
+ unlink(path_str.c_str());
}
int flags = O_WRONLY | O_CREAT | O_TRUNC | O_TEXT;
if (mode == WriteFileMode::exclusive) {
flags |= O_EXCL;
}
- Fd fd(open(path_str, flags, 0666));
+ Fd fd(open(path_str.c_str(), flags, 0666));
if (!fd) {
return tl::unexpected(strerror(errno));
}
nonstd::span<const uint8_t> data,
WriteFileMode mode)
{
- auto path_str = pstr(path);
+ util::PathString path_str(path);
if (mode == WriteFileMode::unlink) {
- unlink(path_str);
+ unlink(path_str.c_str());
}
int flags = O_WRONLY | O_CREAT | O_TRUNC | O_BINARY;
if (mode == WriteFileMode::exclusive) {
flags |= O_EXCL;
}
- Fd fd(open(path_str, flags, 0666));
+ Fd fd(open(path_str.c_str(), flags, 0666));
if (!fd) {
return tl::unexpected(strerror(errno));
}
#include "path.hpp"
#include <ccache/util/DirEntry.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
#include <ccache/util/string.hpp>
namespace fs = util::filesystem;
-using pstr = util::PathString;
-
namespace util {
std::string
std::sort(relpath_candidates.begin(),
relpath_candidates.end(),
[](const auto& path1, const auto& path2) {
- return pstr(path1).str().length() < pstr(path2).str().length();
+ return util::pstr(path1).str().length()
+ < util::pstr(path2).str().length();
});
for (const auto& relpath : relpath_candidates) {
if (fs::equivalent(relpath, closest_existing_path)) {
#pragma once
+#include <ccache/util/PathString.hpp>
+
#include <filesystem>
#include <string>
#include <string_view>
bool path_starts_with(const std::filesystem::path& path,
const std::filesystem::path& prefix);
+// Access the underlying path string without having to copy it if
+// std::filesystem::path::value_type is char (that is, not wchar_t).
+using pstr = PathString;
+
// --- Inline implementations ---
inline bool
#include <ccache/Context.hpp>
#include <ccache/Depfile.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
+#include <ccache/util/path.hpp>
#include <doctest/doctest.h>
namespace fs = util::filesystem;
using TestUtil::TestContext;
-using pstr = util::PathString;
TEST_SUITE_BEGIN("Depfile");
"\n"
" {0}/bar/bar.h: \n"
" {1}/fie.h:\n",
- Depfile::escape_filename(pstr(cwd).str()),
- Depfile::escape_filename(pstr(cwd.parent_path()).str()));
+ Depfile::escape_filename(util::pstr(cwd).str()),
+ Depfile::escape_filename(util::pstr(cwd.parent_path()).str()));
SUBCASE("Base directory not in dep file content")
{
" {1}/fie.h\n"
"{2}:\n"
"{1}/fie.h:\n",
- Depfile::escape_filename(pstr(cwd).str()),
- Depfile::escape_filename(pstr(cwd.parent_path()).str()),
+ Depfile::escape_filename(util::pstr(cwd).str()),
+ Depfile::escape_filename(util::pstr(cwd.parent_path()).str()),
Depfile::escape_filename(
- pstr(fs::path("bar/bar.h").lexically_normal()).str()));
+ util::pstr(fs::path("bar/bar.h").lexically_normal()).str()));
REQUIRE(actual);
CHECK(*actual == expected);
}
#include <ccache/Hash.hpp>
#include <ccache/InodeCache.hpp>
#include <ccache/util/Fd.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/TemporaryFile.hpp>
#include <ccache/util/file.hpp>
#include <ccache/util/filesystem.hpp>
namespace fs = util::filesystem;
using TestUtil::TestContext;
-using pstr = util::PathString;
namespace {
{
config.set_debug(true);
config.set_inode_cache(true);
- config.set_temporary_dir(pstr(*fs::current_path()).str());
+ config.set_temporary_dir(util::pstr(*fs::current_path()));
}
bool
#include <ccache/Context.hpp>
#include <ccache/argprocessing.hpp>
#include <ccache/core/Statistic.hpp>
-#include <ccache/util/PathString.hpp>
#include <ccache/util/file.hpp>
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
using core::Statistic;
using TestUtil::TestContext;
-using pstr = util::PathString;
namespace {
return "/";
#else
char volume[4]; // "C:\"
- GetVolumePathName(pstr(*fs::current_path()).c_str(), volume, sizeof(volume));
+ GetVolumePathName(
+ util::pstr(*fs::current_path()).c_str(), volume, sizeof(volume));
return volume;
#endif
}
#include "TestUtil.hpp"
-#include <ccache/util/PathString.hpp>
#include <ccache/util/environment.hpp>
#include <ccache/util/filesystem.hpp>
#include <ccache/util/format.hpp>
namespace fs = util::filesystem;
-using pstr = util::PathString;
using TestUtil::TestContext;
TEST_CASE("util::add_exe_suffix")
const TestContext test_context;
- const std::string cwd = pstr(*fs::current_path()).str();
+ const std::string cwd = util::pstr(*fs::current_path());
const std::string actual_cwd = FMT("{}/d", cwd);
#if defined(_WIN32) || defined(__CYGWIN__)
const std::string apparent_cwd = actual_cwd;