]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Pass Config instead of Context to Result::Writer
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 4 Sep 2022 11:07:49 +0000 (13:07 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 6 Sep 2022 06:13:28 +0000 (08:13 +0200)
src/Result.cpp
src/Result.hpp
src/ResultRetriever.cpp
src/Util.cpp
src/Util.hpp
src/ccache.cpp

index 7eb7777d5e8de24a904c95da70a5e82193b1edc2..9f7204f275bc3723e333a842654c97c469f93a5a 100644 (file)
@@ -287,8 +287,8 @@ Reader::read_entry(uint8_t entry_number, Reader::Consumer& consumer)
   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)
 {
 }
@@ -334,11 +334,11 @@ Writer::do_finalize()
 
   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());
@@ -349,9 +349,8 @@ Writer::do_finalize()
 
   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()
@@ -425,7 +424,7 @@ Result::Writer::write_raw_file_entry(const std::string& path,
   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()));
index 6e537a8c1f4cbf9b4fbdf0e2c495f11fc06da2a8..a67d71066ed48e0f272da1c6233668924843e1ea 100644 (file)
@@ -134,7 +134,7 @@ private:
 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);
@@ -155,7 +155,7 @@ private:
     std::string value;
   };
 
-  Context& m_ctx;
+  const Config& m_config;
   const std::string m_result_path;
   std::vector<Entry> m_entries_to_write;
 
index bc456bfb4ce6f8975108445c12538c8f0cfc6696..5e2ec0f62b35bc54ed5457fb162ca19342a3fd67 100644 (file)
@@ -121,7 +121,8 @@ ResultRetriever::on_entry_start(uint8_t entry_number,
   } 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).
index cbe9ed5c0f8908e319513bf72744c81a70165654..d389a40b81cd362c3b2b9063fe5f3cd1518f3775 100644 (file)
@@ -25,6 +25,7 @@
 #include "TemporaryFile.hpp"
 #include "Win32Util.hpp"
 
+#include <Config.hpp>
 #include <Finalizer.hpp>
 #include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
@@ -268,12 +269,12 @@ clone_file(const std::string& src, const std::string& dest, bool via_tmp_file)
 #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 {
@@ -286,7 +287,7 @@ clone_hard_link_or_copy_file(const Context& ctx,
     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);
index fbbd4079c34f5767ab50529262c347a4a594920c..2b2f0c1fffb3753caca05a24d819c525c5e2bd15 100644 (file)
@@ -31,6 +31,7 @@
 #include <utility>
 #include <vector>
 
+class Config;
 class Context;
 
 namespace Util {
@@ -87,7 +88,7 @@ void clone_file(const std::string& src,
 // 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);
index 0d052eea927e8b6757b9bdf43e381c06115e7ef7..afbce17b296a645726d190f0f5659c9ce413c8d2 100644 (file)
@@ -880,7 +880,7 @@ write_result(Context& ctx,
              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);