const auto raw_file = get_raw_file_path(m_result_path, entry_number);
const auto old_stat = Stat::stat(raw_file);
try {
- Util::clone_hard_link_or_copy_file(m_ctx.config, path, raw_file, true);
+ Util::clone_hard_link_or_copy_file(m_ctx, path, raw_file, true);
} catch (core::Error& e) {
throw core::Error(
"Failed to store {} as raw file {}: {}", path, raw_file, e.what());
} else if (dest_path == "/dev/null") {
LOG_RAW("Not writing to /dev/null");
} else if (raw_file) {
- Util::clone_hard_link_or_copy_file(
- m_ctx.config, *raw_file, dest_path, false);
+ Util::clone_hard_link_or_copy_file(m_ctx, *raw_file, dest_path, false);
// Update modification timestamp to save the file from LRU cleanup (and, if
// hard-linked, to make the object file newer than the source file).
}
#endif // FILE_CLONING_SUPPORTED
-static void
-clone_hard_link_or_copy_file(const std::string& source,
+void
+clone_hard_link_or_copy_file(const Context& ctx,
+ const std::string& source,
const std::string& dest,
- bool try_clone,
- bool try_hard_link,
bool via_tmp_file)
{
- if (try_clone) {
+ if (ctx.config.file_clone()) {
#ifdef FILE_CLONING_SUPPORTED
LOG("Cloning {} to {}", source, dest);
try {
LOG("Not cloning {} to {} since it's unsupported", source, dest);
#endif
}
- if (try_hard_link) {
+ if (ctx.config.hard_link()) {
LOG("Hard linking {} to {}", source, dest);
try {
Util::hard_link(source, dest);
copy_file(source, dest, via_tmp_file);
}
-void
-clone_hard_link_or_copy_file(const Config& config,
- const std::string& source,
- const std::string& dest,
- bool via_tmp_file)
-{
- clone_hard_link_or_copy_file(
- source, dest, config.file_clone(), config.hard_link(), via_tmp_file);
-}
-
size_t
common_dir_prefix_length(std::string_view dir, std::string_view path)
{
#endif
}
-void
-hard_link_or_copy(const std::string& oldpath, const std::string& newpath)
-{
- return clone_hard_link_or_copy_file(oldpath, newpath, false, true, false);
-}
-
std::optional<size_t>
is_absolute_path_with_prefix(std::string_view path)
{
#include <utility>
#include <vector>
-class Config;
class Context;
namespace Util {
// Clone, hard link or copy a file from `source` to `dest` depending on settings
// in `ctx`. If cloning or hard linking cannot and should not be done the file
// will be copied instead. Throws `core::Error` on error.
-void clone_hard_link_or_copy_file(const Config& config,
+void clone_hard_link_or_copy_file(const Context& ctx,
const std::string& source,
const std::string& dest,
bool via_tmp_file = false);
// Hard-link `oldpath` to `newpath`. Throws `core::Error` on error.
void hard_link(const std::string& oldpath, const std::string& newpath);
-// Hard-link `oldpath` to `newpath`, or fall back to copying if hard-linking
-// doesn't work. Throws `core::Error` on error.
-void hard_link_or_copy(const std::string& oldpath, const std::string& newpath);
-
// Write bytes in big endian order from an integer value.
//
// Parameters:
// stdout_path needs the proper cpp_extension for the compiler to do its
// thing correctly.
stdout_path = FMT("{}.{}", tmp_stdout.path, ctx.config.cpp_extension());
- Util::hard_link_or_copy(tmp_stdout.path, stdout_path);
+ Util::hard_link(tmp_stdout.path, stdout_path);
ctx.register_pending_tmp_file(stdout_path);
TemporaryFile tmp_stderr(