]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
fix: Don't reshare results with raw files to secondary storage
authorJoel Rosdahl <joel@rosdahl.net>
Mon, 12 Sep 2022 13:25:42 +0000 (15:25 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 21 Sep 2022 15:06:31 +0000 (17:06 +0200)
src/storage/Storage.cpp
test/suites/secondary_file.bash

index 9382e025f7c527d747e92dbeb31a49bfa4ddb37e..c468a2e91b15b2cabcbada6b45ac6466263bcd7f 100644 (file)
@@ -32,6 +32,7 @@
 #ifdef HAVE_REDIS_STORAGE_BACKEND
 #  include <storage/secondary/RedisStorage.hpp>
 #endif
+#include <core/CacheEntry.hpp>
 #include <util/Bytes.hpp>
 #include <util/Timer.hpp>
 #include <util/Tokenizer.hpp>
@@ -465,6 +466,12 @@ Storage::put_in_secondary_storage(const Digest& key,
 {
   MTR_SCOPE("secondary_storage", "put");
 
+  if (!core::CacheEntry::Header(value).self_contained) {
+    LOG("Not putting {} in secondary storage since it's not self-contained",
+        key.to_string());
+    return;
+  }
+
   for (const auto& entry : m_secondary_storages) {
     auto backend = get_backend(*entry, key, "putting in", true);
     if (!backend) {
index e432dd7e3bf27abe1047e12a83b5401eaa22d811..9d958c99c5bd462f5f651176ff4cced0c666d8fa 100644 (file)
@@ -268,4 +268,28 @@ SUITE_secondary_file() {
     expect_stat primary_storage_miss 2 # Try to read manifest for updating
     expect_stat secondary_storage_hit 1 # Read manifest for updating
     expect_stat secondary_storage_miss 1
+
+    # -------------------------------------------------------------------------
+    if touch test.c && ln test.c test-if-fs-supports-hard-links.c 2>/dev/null; then
+        TEST "Don't reshare results with raw files"
+
+        CCACHE_SECONDARY_STORAGE= CCACHE_HARDLINK=1 $CCACHE_COMPILE -c test.c
+        expect_stat direct_cache_hit 0
+        expect_stat cache_miss 1
+        expect_stat files_in_cache 3
+        expect_stat primary_storage_hit 0
+        expect_stat primary_storage_miss 2 # result + manifest
+        expect_stat secondary_storage_hit 0
+        expect_stat secondary_storage_miss 0
+
+        CCACHE_RESHARE=1 $CCACHE_COMPILE -c test.c
+        expect_stat direct_cache_hit 1
+        expect_stat cache_miss 1
+        expect_stat files_in_cache 3
+        expect_stat primary_storage_hit 2
+        expect_stat primary_storage_miss 2 # result + manifest
+        expect_stat secondary_storage_hit 0
+        expect_stat secondary_storage_miss 0
+        expect_file_count 2 '*' secondary # CACHEDIR.TAG + manifest, not result
+    fi
 }