]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
enhance: Only keep atime if needed
authorJoel Rosdahl <joel@rosdahl.net>
Thu, 10 Nov 2022 09:15:12 +0000 (10:15 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Sun, 27 Nov 2022 20:33:50 +0000 (21:33 +0100)
- For the --recompress case, only reset timestamps if mtime has changed
  since local cache LRU cleanup always uses mtime.
- For the --trim-dir/--trim-recompress case, always reset timestamps
  since atime may be used for LRU cleanup.

src/core/FileRecompressor.cpp
src/core/FileRecompressor.hpp
src/core/mainoptions.cpp
src/storage/local/LocalStorage_compress.cpp

index 03818b013619337506ea6f9239d10febd5ab04ed..131a85f95b4850f73ce6394150cc750b313a890e 100644 (file)
@@ -29,7 +29,8 @@ namespace core {
 
 int64_t
 FileRecompressor::recompress(const std::string& cache_file,
-                             const std::optional<int8_t> level)
+                             std::optional<int8_t> level,
+                             KeepAtime keep_atime)
 {
   core::CacheEntry::Header header(cache_file);
 
@@ -59,7 +60,9 @@ FileRecompressor::recompress(const std::string& cache_file,
   }
 
   // Restore mtime/atime to keep cache LRU cleanup working as expected:
-  util::set_timestamps(cache_file, old_stat.mtime(), old_stat.atime());
+  if (keep_atime == KeepAtime::yes || new_stat) {
+    util::set_timestamps(cache_file, old_stat.mtime(), old_stat.atime());
+  }
 
   m_content_size += header.entry_size;
   m_old_size += old_stat.size_on_disk();
index 289b0d75e2de11dbdc67ff865a5ade1fa3eee99c..b2fdb131ba6e8a014c9a10769846df1bbaf51928 100644 (file)
@@ -29,11 +29,14 @@ namespace core {
 class FileRecompressor
 {
 public:
+  enum class KeepAtime { yes, no };
+
   FileRecompressor() = default;
 
   // Returns on-disk size change in KiB.
   int64_t recompress(const std::string& cache_file,
-                     const std::optional<int8_t> level);
+                     const std::optional<int8_t> level,
+                     KeepAtime keep_atime);
 
   uint64_t content_size() const;
   uint64_t old_size() const;
index a1866b5c8fa3d21fa86ce5c324ba989607499ce7..7b3e639adfd1ed6fa91d783d475611ac14b18a92 100644 (file)
@@ -316,7 +316,9 @@ trim_dir(const std::string& dir,
     for (const auto& file : files) {
       thread_pool.enqueue([&] {
         try {
-          recompressor.recompress(file.path, *recompress_level);
+          recompressor.recompress(file.path,
+                                  *recompress_level,
+                                  core::FileRecompressor::KeepAtime::yes);
         } catch (core::Error&) {
           // Ignore for now.
           incompressible_size += file.stat.size_on_disk();
index 4aa587ad91d9d6d2634c5aa105b559fffc17fd12..81caa40b62854b7c4e39337fb54367cd52183d7d 100644 (file)
@@ -110,8 +110,8 @@ LocalStorage::recompress(const std::optional<int8_t> level,
           thread_pool.enqueue(
             [&recompressor, &incompressible_size, level, stats_file, file] {
               try {
-                int64_t size_change_kibibyte =
-                  recompressor.recompress(file.path(), level);
+                int64_t size_change_kibibyte = recompressor.recompress(
+                  file.path(), level, core::FileRecompressor::KeepAtime::no);
                 StatsFile(stats_file).update([=](auto& cs) {
                   cs.increment(core::Statistic::cache_size_kibibyte,
                                size_change_kibibyte);