From 617597c18cb9fae001a82949e552ad31bdccb60d Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Sun, 26 Oct 2025 16:04:53 +0100 Subject: [PATCH] feat: Log errors and size changes when recompressing cache files --- src/ccache/core/mainoptions.cpp | 14 +++++++++++--- src/ccache/storage/local/localstorage.cpp | 15 +++++++++++++-- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/src/ccache/core/mainoptions.cpp b/src/ccache/core/mainoptions.cpp index 647606a4..d00b38b8 100644 --- a/src/ccache/core/mainoptions.cpp +++ b/src/ccache/core/mainoptions.cpp @@ -358,9 +358,17 @@ trim_dir(const std::string& dir, try { auto new_stat = recompressor.recompress( file, *recompress_level, core::FileRecompressor::KeepAtime::yes); - file = std::move(new_stat); // Remember new size, if any. - } catch (core::Error&) { - // Ignore for now. + auto old_size = file.size(); + auto new_size = new_stat.size(); + if (new_size != old_size) { + LOG("Recompressed {} from {} to {} bytes", + file.path(), + old_size, + new_size); + file = std::move(new_stat); // Remember for sum calculation later + } + } catch (core::Error& e) { + LOG("Error when recompressing {}: {}", file.path(), e.what()); incompressible_size += file.size_on_disk(); } }); diff --git a/src/ccache/storage/local/localstorage.cpp b/src/ccache/storage/local/localstorage.cpp index 09dba095..ce2aaeb4 100644 --- a/src/ccache/storage/local/localstorage.cpp +++ b/src/ccache/storage/local/localstorage.cpp @@ -910,6 +910,14 @@ LocalStorage::recompress(const std::optional level, try { DirEntry new_dir_entry = recompressor.recompress( file, level, core::FileRecompressor::KeepAtime::no); + auto old_size = file.size(); + auto new_size = new_dir_entry.size(); + // LOG_RAW+fmt::format instead of LOG due to GCC 12.3 bug + // #109241 + LOG_RAW(fmt::format("Recompressed {} from {} to {} bytes", + file.path(), + old_size, + new_size)); auto size_change_kibibyte = kibibyte_size_diff(file, new_dir_entry); if (size_change_kibibyte != 0) { @@ -922,8 +930,11 @@ LocalStorage::recompress(const std::optional level, size_change_kibibyte); }); } - } catch (core::Error&) { - // Ignore for now. + } catch (core::Error& e) { + // LOG_RAW+fmt::format instead of LOG due to GCC 12.3 bug + // #109241 + LOG_RAW(fmt::format( + "Error when recompressing {}: {}", file.path(), e.what())); incompressible_size += file.size_on_disk(); } }); -- 2.47.3