From: Joel Rosdahl Date: Wed, 8 Jun 2022 15:29:22 +0000 (+0200) Subject: fix: Retain mtime/atime for recompressed files X-Git-Tag: v4.6.2~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=6e1653ac7334dd7cd5453594cc5bba81bb745bec;p=thirdparty%2Fccache.git fix: Retain mtime/atime for recompressed files (cherry picked from commit c57929acd676c577e1abae8aae6467c37ecd7b4b) --- diff --git a/src/storage/primary/PrimaryStorage_compress.cpp b/src/storage/primary/PrimaryStorage_compress.cpp index 4965f224c..ce1e3b190 100644 --- a/src/storage/primary/PrimaryStorage_compress.cpp +++ b/src/storage/primary/PrimaryStorage_compress.cpp @@ -35,6 +35,7 @@ #include #include #include +#include #include #include @@ -188,15 +189,16 @@ recompress_file(RecompressionStatistics& statistics, writer->finalize(); file.close(); - atomic_new_file.commit(); - const auto new_stat = Stat::stat(cache_file.path(), Stat::OnError::log); + // Restore mtime/atime to keep cache LRU cleanup working as expected: + util::set_timestamps(cache_file.path(), old_stat.mtim(), old_stat.atim()); + + const auto new_stat = Stat::stat(cache_file.path(), Stat::OnError::log); StatsFile(stats_file).update([=](auto& cs) { cs.increment(core::Statistic::cache_size_kibibyte, Util::size_change_kibibyte(old_stat, new_stat)); }); - statistics.update(content_size, old_stat.size(), new_stat.size(), 0); LOG("Recompression of {} done", cache_file.path());