From 4798634dd8fd5fd4584a01ec1d116677c2c491a5 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Mon, 12 Sep 2022 15:25:42 +0200 Subject: [PATCH] fix: Don't reshare results with raw files to secondary storage --- src/storage/Storage.cpp | 7 +++++++ test/suites/secondary_file.bash | 24 ++++++++++++++++++++++++ 2 files changed, 31 insertions(+) diff --git a/src/storage/Storage.cpp b/src/storage/Storage.cpp index 9382e025f..c468a2e91 100644 --- a/src/storage/Storage.cpp +++ b/src/storage/Storage.cpp @@ -32,6 +32,7 @@ #ifdef HAVE_REDIS_STORAGE_BACKEND # include #endif +#include #include #include #include @@ -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) { diff --git a/test/suites/secondary_file.bash b/test/suites/secondary_file.bash index e432dd7e3..9d958c99c 100644 --- a/test/suites/secondary_file.bash +++ b/test/suites/secondary_file.bash @@ -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 } -- 2.47.2