]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Move Util::size_change_kibibyte to LocalStorage
authorJoel Rosdahl <joel@rosdahl.net>
Sun, 16 Jul 2023 07:13:52 +0000 (09:13 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 18 Jul 2023 19:35:11 +0000 (21:35 +0200)
src/Config.cpp
src/Util.cpp
src/Util.hpp
src/core/ResultExtractor.cpp
src/storage/local/LocalStorage.cpp
src/storage/remote/FileStorage.cpp
src/util/LockFile.cpp
src/util/path.cpp
unittest/test_Util.cpp

index b508ae4dc35b2f1b0e4f6c13b71b6bd4f3877e8c..ffb722f5db0621b53235b85696baa4dafc2ae622 100644 (file)
@@ -23,6 +23,7 @@
 #include "Util.hpp"
 #include "assertions.hpp"
 
+#include <Stat.hpp>
 #include <core/exceptions.hpp>
 #include <core/types.hpp>
 #include <core/wincompat.hpp>
index a3858a487e7ebfeb75ea6eb62d48076cfb928767..580de30dab8e9fa7849b64a9409f9c4063c2c44b 100644 (file)
@@ -27,6 +27,7 @@
 
 #include <Config.hpp>
 #include <Finalizer.hpp>
+#include <Stat.hpp>
 #include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <fmtmacros.hpp>
index ceed09803759244e15202e40927c0e7b83d3019a..5e8fc8ac7b989cdf989d1a1a5ec5cb6e13f84b0b 100644 (file)
@@ -18,7 +18,6 @@
 
 #pragma once
 
-#include <Stat.hpp>
 #include <util/TimePoint.hpp>
 #include <util/Tokenizer.hpp>
 
@@ -173,15 +172,6 @@ std::string_view remove_extension(std::string_view path);
 // `core::Error` on error.
 void send_to_fd(const Context& ctx, std::string_view text, int fd);
 
-// Return size change in KiB between `old_stat`  and `new_stat`.
-inline int64_t
-size_change_kibibyte(const Stat& old_stat, const Stat& new_stat)
-{
-  return (static_cast<int64_t>(new_stat.size_on_disk())
-          - static_cast<int64_t>(old_stat.size_on_disk()))
-         / 1024;
-}
-
 // Split `string` into tokens at any of the characters in `separators`. These
 // tokens are views into `string`. `separators` must neither be the empty string
 // nor a nullptr.
index 8649ede7018f395efaddf4a7e440f7afa6cb159f..1969876cc58f5ed6d95d6b9b946cc006eda663ec 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -21,6 +21,7 @@
 #include "Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <Stat.hpp>
 #include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <fmtmacros.hpp>
index 9aaf2c6beb41c6b39e90fde7ae32f58ff2a37e46..4513444d52d8b0129d0e681c95582d52877ef766 100644 (file)
@@ -160,6 +160,15 @@ struct Level1Counters
 
 } // namespace
 
+// Return size change in KiB between `old_stat`  and `new_stat`.
+static int64_t
+kibibyte_size_diff(const Stat& old_stat, const Stat& new_stat)
+{
+  return (static_cast<int64_t>(new_stat.size_on_disk())
+          - static_cast<int64_t>(old_stat.size_on_disk()))
+         / 1024;
+}
+
 static void
 set_counters(const StatsFile& stats_file, const Level1Counters& level_1_cs)
 {
@@ -526,8 +535,7 @@ LocalStorage::put(const Hash::Digest& key,
   }
 
   int64_t files_change = cache_file.stat ? 0 : 1;
-  int64_t size_change_kibibyte =
-    Util::size_change_kibibyte(cache_file.stat, new_stat);
+  int64_t size_change_kibibyte = kibibyte_size_diff(cache_file.stat, new_stat);
   auto counters =
     increment_level_2_counters(key, files_change, size_change_kibibyte);
 
@@ -621,7 +629,7 @@ LocalStorage::put_raw_files(
     }
     const auto new_stat = Stat::stat(dest_path);
     increment_statistic(Statistic::cache_size_kibibyte,
-                        Util::size_change_kibibyte(old_stat, new_stat));
+                        kibibyte_size_diff(old_stat, new_stat));
     increment_statistic(Statistic::files_in_cache,
                         (new_stat ? 1 : 0) - (old_stat ? 1 : 0));
   }
@@ -857,7 +865,7 @@ LocalStorage::recompress(const std::optional<int8_t> level,
                   Stat new_stat = recompressor.recompress(
                     file, level, core::FileRecompressor::KeepAtime::no);
                   auto size_change_kibibyte =
-                    Util::size_change_kibibyte(file, new_stat);
+                    kibibyte_size_diff(file, new_stat);
                   if (size_change_kibibyte != 0) {
                     StatsFile(stats_file).update([=](auto& cs) {
                       cs.increment(Statistic::cache_size_kibibyte,
index 4b6125068f56ee0ac8c8821812c1871bea3c422a..917cb2b820b75d3dba88c70810d9ca5c5bd7bd57 100644 (file)
@@ -20,6 +20,7 @@
 
 #include <AtomicFile.hpp>
 #include <Logging.hpp>
+#include <Stat.hpp>
 #include <Util.hpp>
 #include <assertions.hpp>
 #include <core/exceptions.hpp>
index 219a635351150f15692011262b73074ed60f8b49..d9184ef2eb7c3101e110e2a3493db22d390c8548 100644 (file)
@@ -23,6 +23,7 @@
 #include "Win32Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <Stat.hpp>
 #include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <util/file.hpp>
index 1106a6d65ab899cef318679b4b8ea1946eb60534..6d9e55bd43fdc5a62a12876548ec62036dc18504 100644 (file)
@@ -18,6 +18,7 @@
 
 #include "path.hpp"
 
+#include <Stat.hpp>
 #include <Util.hpp>
 #include <fmtmacros.hpp>
 #include <util/filesystem.hpp>
index a8b215d5865f298ea3978ee30f0290338bbf6fa6..6b9168a84865e3c1497b3f320685a1f1d51e4e03 100644 (file)
@@ -22,6 +22,7 @@
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"
 
+#include <Stat.hpp>
 #include <core/exceptions.hpp>
 #include <core/wincompat.hpp>
 #include <util/environment.hpp>