consumer.on_entry_end();
}
-Writer::Writer(Context& ctx, const std::string& result_path)
- : m_ctx(ctx),
+Writer::Writer(const Config& config, const std::string& result_path)
+ : m_config(config),
m_result_path(result_path)
{
}
AtomicFile atomic_result_file(m_result_path, AtomicFile::Mode::binary);
core::CacheEntryHeader header(core::CacheEntryType::result,
- compression::type_from_config(m_ctx.config),
- compression::level_from_config(m_ctx.config),
+ compression::type_from_config(m_config),
+ compression::level_from_config(m_config),
time(nullptr),
CCACHE_VERSION,
- m_ctx.config.namespace_());
+ m_config.namespace_());
header.set_entry_size_from_payload_size(payload_size);
core::FileWriter file_writer(atomic_result_file.stream());
uint8_t entry_number = 0;
for (const auto& entry : m_entries_to_write) {
- const bool store_raw =
- entry.value_type == ValueType::path
- && should_store_raw_file(m_ctx.config, entry.file_type);
+ const bool store_raw = entry.value_type == ValueType::path
+ && should_store_raw_file(m_config, entry.file_type);
const uint64_t entry_size =
entry.value_type == ValueType::data
? entry.value.size()
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, path, raw_file, true);
+ Util::clone_hard_link_or_copy_file(m_config, path, raw_file, true);
} catch (core::Error& e) {
throw core::Error(
FMT("Failed to store {} as raw file {}: {}", path, raw_file, e.what()));
class Writer
{
public:
- Writer(Context& ctx, const std::string& result_path);
+ Writer(const Config& config, const std::string& result_path);
// Register content to include in the result. Does not throw.
void write_data(FileType file_type, const std::string& data);
std::string value;
};
- Context& m_ctx;
+ const Config& m_config;
const std::string m_result_path;
std::vector<Entry> m_entries_to_write;
} 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, *raw_file, dest_path, false);
+ Util::clone_hard_link_or_copy_file(
+ m_ctx.config, *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).
#include "TemporaryFile.hpp"
#include "Win32Util.hpp"
+#include <Config.hpp>
#include <Finalizer.hpp>
#include <core/exceptions.hpp>
#include <core/wincompat.hpp>
#endif // FILE_CLONING_SUPPORTED
void
-clone_hard_link_or_copy_file(const Context& ctx,
+clone_hard_link_or_copy_file(const Config& config,
const std::string& source,
const std::string& dest,
bool via_tmp_file)
{
- if (ctx.config.file_clone()) {
+ if (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 (ctx.config.hard_link()) {
+ if (config.hard_link()) {
LOG("Hard linking {} to {}", source, dest);
try {
Util::hard_link(source, dest);
#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 Context& ctx,
+void clone_hard_link_or_copy_file(const Config& config,
const std::string& source,
const std::string& dest,
bool via_tmp_file = false);
const std::string& stdout_data,
const std::string& stderr_data)
{
- Result::Writer result_writer(ctx, result_path);
+ Result::Writer result_writer(ctx.config, result_path);
if (!stderr_data.empty()) {
result_writer.write_data(Result::FileType::stderr_output, stderr_data);