]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Rename raw files correctly for >2 cache levels
authorOded S <oded@istraresearch.com>
Thu, 27 Feb 2025 19:22:47 +0000 (21:22 +0200)
committerGitHub <noreply@github.com>
Thu, 27 Feb 2025 19:22:47 +0000 (20:22 +0100)
LocalStorage::move_to_wanted_cache_level renames raw files incorrectly without
recalculating full hash filename with new prefix.

src/ccache/storage/local/localstorage.cpp
src/ccache/storage/local/localstorage.hpp

index aa9d87dd65a16cd98d3d2a9ef5bf6b25f8c050b3..89a51a02a1775e6a32bfb98f3de5218b4cb6d5f5 100644 (file)
@@ -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));
     }
   }
 }
index 558227271c5430686e2bd39eb257a4f23e51a785..01b8861acbfa266785c799196d886608f2841f9a 100644 (file)
@@ -138,7 +138,12 @@ private:
   // a statistics file in the finalize method.
   core::StatisticsCounters m_counter_updates;
 
-  std::vector<std::filesystem::path> m_added_raw_files;
+  struct AddedRawFile
+  {
+    uint8_t file_number;
+    std::filesystem::path dest_path;
+  };
+  std::vector<AddedRawFile> m_added_raw_files;
   bool m_stored_data = false;
 
   struct LookUpCacheFileResult