]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Retain mtime/atime for recompressed files
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 8 Jun 2022 15:29:22 +0000 (17:29 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Sat, 20 Aug 2022 11:51:18 +0000 (13:51 +0200)
(cherry picked from commit c57929acd676c577e1abae8aae6467c37ecd7b4b)

src/storage/primary/PrimaryStorage_compress.cpp

index 4965f224c0fcc4bcd99a7001ab128c3bc3df7e3d..ce1e3b1902d777534fe330905bf5c3c2a04f3e2c 100644 (file)
@@ -35,6 +35,7 @@
 #include <core/wincompat.hpp>
 #include <fmtmacros.hpp>
 #include <storage/primary/StatsFile.hpp>
+#include <util/file.hpp>
 #include <util/string.hpp>
 
 #include <third_party/fmt/core.h>
@@ -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());