diff options
author | Joel Rosdahl <joel@rosdahl.net> | 2022-11-10 10:15:12 +0100 |
---|---|---|
committer | Joel Rosdahl <joel@rosdahl.net> | 2022-11-27 21:33:50 +0100 |
commit | 0437820b47abe55e49f5fdb2ed189c4a1f23a611 (patch) | |
tree | 87d018fcfbcc735dafed114367e4e70c6b154560 /src/core | |
parent | 5d47a49ca00071f6660aa042012e4d35a0a0c651 (diff) | |
download | ccache-0437820b47abe55e49f5fdb2ed189c4a1f23a611.tar.gz |
enhance: Only keep atime if needed
- 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.
Diffstat (limited to 'src/core')
-rw-r--r-- | src/core/FileRecompressor.cpp | 7 | ||||
-rw-r--r-- | src/core/FileRecompressor.hpp | 5 | ||||
-rw-r--r-- | src/core/mainoptions.cpp | 4 |
3 files changed, 12 insertions, 4 deletions
diff --git a/src/core/FileRecompressor.cpp b/src/core/FileRecompressor.cpp index 03818b01..131a85f9 100644 --- a/src/core/FileRecompressor.cpp +++ b/src/core/FileRecompressor.cpp @@ -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(); diff --git a/src/core/FileRecompressor.hpp b/src/core/FileRecompressor.hpp index 289b0d75..b2fdb131 100644 --- a/src/core/FileRecompressor.hpp +++ b/src/core/FileRecompressor.hpp @@ -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; diff --git a/src/core/mainoptions.cpp b/src/core/mainoptions.cpp index a1866b5c..7b3e639a 100644 --- a/src/core/mainoptions.cpp +++ b/src/core/mainoptions.cpp @@ -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(); |