]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Convert primary storage to a public member of storage::Storage
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 22 Jul 2021 14:20:01 +0000 (16:20 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Thu, 22 Jul 2021 20:32:30 +0000 (22:32 +0200)
src/ccache.cpp
src/storage/Storage.cpp
src/storage/Storage.hpp

index d586842a260d8fb3cecabb0ff3a2c93371ae49b0..f5e4b19d3fb1f148c045909a456137fcfd092f83 100644 (file)
@@ -906,10 +906,10 @@ write_result(Context& ctx,
 
   const auto file_size_and_count_diff = result_writer.finalize();
   if (file_size_and_count_diff) {
-    ctx.storage.primary().increment_statistic(
+    ctx.storage.primary.increment_statistic(
       Statistic::cache_size_kibibyte, file_size_and_count_diff->size_kibibyte);
-    ctx.storage.primary().increment_statistic(Statistic::files_in_cache,
-                                              file_size_and_count_diff->count);
+    ctx.storage.primary.increment_statistic(Statistic::files_in_cache,
+                                            file_size_and_count_diff->count);
   } else {
     LOG("Error: {}", file_size_and_count_diff.error());
     throw Failure(Statistic::internal_error);
@@ -1919,7 +1919,7 @@ log_result_to_debug_log(Context& ctx)
     return;
   }
 
-  core::Statistics statistics(ctx.storage.primary().get_statistics_updates());
+  core::Statistics statistics(ctx.storage.primary.get_statistics_updates());
   const auto result_message = statistics.get_result_message();
   if (result_message) {
     LOG("Result: {}", *result_message);
@@ -1933,7 +1933,7 @@ log_result_to_stats_log(Context& ctx)
     return;
   }
 
-  core::Statistics statistics(ctx.storage.primary().get_statistics_updates());
+  core::Statistics statistics(ctx.storage.primary.get_statistics_updates());
   const auto result_id = statistics.get_result_id();
   if (!result_id) {
     return;
@@ -1993,10 +1993,10 @@ cache_compilation(int argc, const char* const* argv)
 
     try {
       Statistic statistic = do_cache_compilation(ctx, argv);
-      ctx.storage.primary().increment_statistic(statistic);
+      ctx.storage.primary.increment_statistic(statistic);
     } catch (const Failure& e) {
       if (e.statistic() != Statistic::none) {
-        ctx.storage.primary().increment_statistic(e.statistic());
+        ctx.storage.primary.increment_statistic(e.statistic());
       }
 
       if (e.exit_code()) {
@@ -2339,7 +2339,7 @@ handle_main_options(int argc, const char* const* argv)
     case EVICT_OLDER_THAN: {
       auto seconds = Util::parse_duration(arg);
       ProgressBar progress_bar("Evicting...");
-      ctx.storage.primary().clean_old(
+      ctx.storage.primary.clean_old(
         [&](double progress) { progress_bar.update(progress); }, seconds);
       if (isatty(STDOUT_FILENO)) {
         PRINT_RAW(stdout, "\n");
@@ -2372,7 +2372,7 @@ handle_main_options(int argc, const char* const* argv)
       core::StatisticsCounters counters;
       time_t last_updated;
       std::tie(counters, last_updated) =
-        ctx.storage.primary().get_all_statistics();
+        ctx.storage.primary.get_all_statistics();
       core::Statistics statistics(counters);
       PRINT_RAW(stdout, statistics.format_machine_readable(last_updated));
       break;
@@ -2381,7 +2381,7 @@ handle_main_options(int argc, const char* const* argv)
     case 'c': // --cleanup
     {
       ProgressBar progress_bar("Cleaning...");
-      ctx.storage.primary().clean_all(
+      ctx.storage.primary.clean_all(
         [&](double progress) { progress_bar.update(progress); });
       if (isatty(STDOUT_FILENO)) {
         PRINT_RAW(stdout, "\n");
@@ -2392,7 +2392,7 @@ handle_main_options(int argc, const char* const* argv)
     case 'C': // --clear
     {
       ProgressBar progress_bar("Clearing...");
-      ctx.storage.primary().wipe_all(
+      ctx.storage.primary.wipe_all(
         [&](double progress) { progress_bar.update(progress); });
       if (isatty(STDOUT_FILENO)) {
         PRINT_RAW(stdout, "\n");
@@ -2475,7 +2475,7 @@ handle_main_options(int argc, const char* const* argv)
       core::StatisticsCounters counters;
       time_t last_updated;
       std::tie(counters, last_updated) =
-        ctx.storage.primary().get_all_statistics();
+        ctx.storage.primary.get_all_statistics();
       core::Statistics statistics(counters);
       PRINT_RAW(stdout, statistics.format_config_header(ctx.config));
       PRINT_RAW(stdout, statistics.format_human_readable(last_updated, false));
@@ -2490,7 +2490,7 @@ handle_main_options(int argc, const char* const* argv)
     case 'x': // --show-compression
     {
       ProgressBar progress_bar("Scanning...");
-      ctx.storage.primary().print_compression_statistics(
+      ctx.storage.primary.print_compression_statistics(
         [&](double progress) { progress_bar.update(progress); });
       break;
     }
@@ -2506,13 +2506,13 @@ handle_main_options(int argc, const char* const* argv)
       }
 
       ProgressBar progress_bar("Recompressing...");
-      ctx.storage.primary().recompress(
+      ctx.storage.primary.recompress(
         wanted_level, [&](double progress) { progress_bar.update(progress); });
       break;
     }
 
     case 'z': // --zero-stats
-      ctx.storage.primary().zero_all_statistics();
+      ctx.storage.primary.zero_all_statistics();
       PRINT_RAW(stdout, "Statistics zeroed\n");
       break;
 
index 51b51b7c26b884ffb58603a30aa1445b7d0690de..31623902378258b8c7610c2142b474a2baa7c52f 100644 (file)
@@ -155,9 +155,7 @@ get_storage(const Url& url)
   }
 }
 
-Storage::Storage(const Config& config)
-  : m_config(config),
-    m_primary_storage(config)
+Storage::Storage(const Config& config) : primary(config), m_config(config)
 {
 }
 
@@ -171,20 +169,20 @@ Storage::~Storage()
 void
 Storage::initialize()
 {
-  m_primary_storage.initialize();
+  primary.initialize();
   add_secondary_storages();
 }
 
 void
 Storage::finalize()
 {
-  m_primary_storage.finalize();
+  primary.finalize();
 }
 
 nonstd::optional<std::string>
 Storage::get(const Digest& key, const core::CacheEntryType type)
 {
-  const auto path = m_primary_storage.get(key, type);
+  const auto path = primary.get(key, type);
   if (path) {
     return path;
   }
@@ -202,7 +200,7 @@ Storage::get(const Digest& key, const core::CacheEntryType type)
     throw core::Fatal("Error writing to {}: {}", tmp_file.path, e.what());
   }
 
-  m_primary_storage.put(key, type, [&](const std::string& path) {
+  primary.put(key, type, [&](const std::string& path) {
     try {
       Util::copy_file(tmp_file.path, path);
     } catch (const core::Error& e) {
@@ -220,7 +218,7 @@ Storage::put(const Digest& key,
              const core::CacheEntryType type,
              const storage::EntryWriter& entry_writer)
 {
-  const auto path = m_primary_storage.put(key, type, entry_writer);
+  const auto path = primary.put(key, type, entry_writer);
   if (!path) {
     return false;
   }
@@ -250,7 +248,7 @@ Storage::put(const Digest& key,
 void
 Storage::remove(const Digest& key, const core::CacheEntryType type)
 {
-  m_primary_storage.remove(key, type);
+  primary.remove(key, type);
   remove_from_secondary_storage(key);
 }
 
index e3d10c696613aebbcedbe730f6cb597dac1fd0e9..fe905fd39af52cc1e03d53c785a121e6e3b00327 100644 (file)
@@ -46,7 +46,7 @@ public:
   void initialize();
   void finalize();
 
-  primary::PrimaryStorage& primary();
+  primary::PrimaryStorage primary;
 
   // Returns a path to a file containing the value.
   nonstd::optional<std::string> get(const Digest& key,
@@ -62,7 +62,6 @@ public:
 
 private:
   const Config& m_config;
-  primary::PrimaryStorage m_primary_storage;
   std::vector<std::unique_ptr<SecondaryStorageEntry>> m_secondary_storages;
   std::vector<std::string> m_tmp_files;
 
@@ -72,10 +71,4 @@ private:
   void remove_from_secondary_storage(const Digest& key);
 };
 
-inline primary::PrimaryStorage&
-Storage::primary()
-{
-  return m_primary_storage;
-}
-
 } // namespace storage