From: Joel Rosdahl Date: Wed, 11 Mar 2026 19:05:11 +0000 (+0100) Subject: fix: Fix restoring of timestamps in recompressor X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f5020efc264a76c81004c19c78a659c21fce1654;p=thirdparty%2Fccache.git fix: Fix restoring of timestamps in recompressor Fixes incorrect fix in 86af29da704f0e879c55230aad9a22d5df330bc3. --- diff --git a/src/ccache/core/filerecompressor.cpp b/src/ccache/core/filerecompressor.cpp index cd5cd6df..83767d12 100644 --- a/src/ccache/core/filerecompressor.cpp +++ b/src/ccache/core/filerecompressor.cpp @@ -1,4 +1,4 @@ -// Copyright (C) 2022-2024 Joel Rosdahl and other contributors +// Copyright (C) 2022-2026 Joel Rosdahl and other contributors // // See doc/authors.adoc for a complete list of contributors. // @@ -35,21 +35,28 @@ FileRecompressor::recompress(const DirEntry& dir_entry, std::optional level, KeepAtime keep_atime) { - core::CacheEntry::Header header(dir_entry.path()); - - const int8_t wanted_level = - level ? (*level == 0 ? core::CacheEntry::default_compression_level : *level) - : 0; - std::optional new_dir_entry; - // Restore mtime/atime to keep cache LRU cleanup working as expected: - DEFER([&] { + // Restore mtime/atime to keep cache LRU cleanup working as expected. + // + // - For the --trim-dir/--trim-recompress case, always reset timestamps since + // atime may be used for LRU cleanup (keep_atime == KeepAtime::yes). + // - For the --recompress case, only reset timestamps if mtime has changed + // since local cache LRU cleanup always uses mtime (new_cache_file.commit() + // has succeeded so new_dir_entry exists). + auto restore_timestamps = [&] { if (keep_atime == KeepAtime::yes || new_dir_entry) { util::set_timestamps( dir_entry.path(), dir_entry.mtime(), dir_entry.atime()); } - }); + }; + DEFER(restore_timestamps()); + + core::CacheEntry::Header header(dir_entry.path()); + + const int8_t wanted_level = + level ? (*level == 0 ? core::CacheEntry::default_compression_level : *level) + : 0; if (header.compression_level != wanted_level) { const auto cache_file_data = util::value_or_throw(