From: Joel Rosdahl Date: Sun, 16 Jul 2023 07:13:52 +0000 (+0200) Subject: refactor: Move Util::size_change_kibibyte to LocalStorage X-Git-Tag: v4.9~120 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a999edfb9401fd54a8dc7d94676bd64f0e0bea83;p=thirdparty%2Fccache.git refactor: Move Util::size_change_kibibyte to LocalStorage --- diff --git a/src/Config.cpp b/src/Config.cpp index b508ae4dc..ffb722f5d 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -23,6 +23,7 @@ #include "Util.hpp" #include "assertions.hpp" +#include #include #include #include diff --git a/src/Util.cpp b/src/Util.cpp index a3858a487..580de30da 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -27,6 +27,7 @@ #include #include +#include #include #include #include diff --git a/src/Util.hpp b/src/Util.hpp index ceed09803..5e8fc8ac7 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -18,7 +18,6 @@ #pragma once -#include #include #include @@ -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(new_stat.size_on_disk()) - - static_cast(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. diff --git a/src/core/ResultExtractor.cpp b/src/core/ResultExtractor.cpp index 8649ede70..1969876cc 100644 --- a/src/core/ResultExtractor.cpp +++ b/src/core/ResultExtractor.cpp @@ -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 #include #include #include diff --git a/src/storage/local/LocalStorage.cpp b/src/storage/local/LocalStorage.cpp index 9aaf2c6be..4513444d5 100644 --- a/src/storage/local/LocalStorage.cpp +++ b/src/storage/local/LocalStorage.cpp @@ -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(new_stat.size_on_disk()) + - static_cast(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 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, diff --git a/src/storage/remote/FileStorage.cpp b/src/storage/remote/FileStorage.cpp index 4b6125068..917cb2b82 100644 --- a/src/storage/remote/FileStorage.cpp +++ b/src/storage/remote/FileStorage.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include #include diff --git a/src/util/LockFile.cpp b/src/util/LockFile.cpp index 219a63535..d9184ef2e 100644 --- a/src/util/LockFile.cpp +++ b/src/util/LockFile.cpp @@ -23,6 +23,7 @@ #include "Win32Util.hpp" #include "fmtmacros.hpp" +#include #include #include #include diff --git a/src/util/path.cpp b/src/util/path.cpp index 1106a6d65..6d9e55bd4 100644 --- a/src/util/path.cpp +++ b/src/util/path.cpp @@ -18,6 +18,7 @@ #include "path.hpp" +#include #include #include #include diff --git a/unittest/test_Util.cpp b/unittest/test_Util.cpp index a8b215d58..6b9168a84 100644 --- a/unittest/test_Util.cpp +++ b/unittest/test_Util.cpp @@ -22,6 +22,7 @@ #include "../src/fmtmacros.hpp" #include "TestUtil.hpp" +#include #include #include #include