From: Oded S Date: Thu, 27 Feb 2025 19:22:47 +0000 (+0200) Subject: fix: Rename raw files correctly for >2 cache levels X-Git-Tag: v4.11~17 X-Git-Url: http://git.ipfire.org/gitweb/gitweb.cgi?a=commitdiff_plain;h=ee0b521393840bec7c55ab8e8147645abf82ba72;p=thirdparty%2Fccache.git fix: Rename raw files correctly for >2 cache levels LocalStorage::move_to_wanted_cache_level renames raw files incorrectly without recalculating full hash filename with new prefix. --- diff --git a/src/ccache/storage/local/localstorage.cpp b/src/ccache/storage/local/localstorage.cpp index aa9d87dd..89a51a02 100644 --- a/src/ccache/storage/local/localstorage.cpp +++ b/src/ccache/storage/local/localstorage.cpp @@ -656,7 +656,7 @@ LocalStorage::put_raw_files( old_dir_entry.refresh(); try { clone_hard_link_or_copy_file(source_path, dest_path, true); - m_added_raw_files.push_back(dest_path); + m_added_raw_files.push_back(AddedRawFile{file_number, dest_path}); } catch (core::Error& e) { LOG("Failed to store {} as raw file {}: {}", source_path, @@ -1082,9 +1082,8 @@ LocalStorage::move_to_wanted_cache_level(const StatisticsCounters& counters, // to rename is OK. LOG("Moving {} to {}", cache_file_path, wanted_path); fs::rename(cache_file_path, wanted_path); - for (const auto& raw_file : m_added_raw_files) { - fs::rename(raw_file, - FMT("{}/{}", wanted_path.parent_path(), raw_file.filename())); + for (auto [file_number, dest_path] : m_added_raw_files) { + fs::rename(dest_path, get_raw_file_path(wanted_path, file_number)); } } } diff --git a/src/ccache/storage/local/localstorage.hpp b/src/ccache/storage/local/localstorage.hpp index 55822727..01b8861a 100644 --- a/src/ccache/storage/local/localstorage.hpp +++ b/src/ccache/storage/local/localstorage.hpp @@ -138,7 +138,12 @@ private: // a statistics file in the finalize method. core::StatisticsCounters m_counter_updates; - std::vector m_added_raw_files; + struct AddedRawFile + { + uint8_t file_number; + std::filesystem::path dest_path; + }; + std::vector m_added_raw_files; bool m_stored_data = false; struct LookUpCacheFileResult