} catch (const Error& e) {
throw Fatal("Error writing to {}: {}", tmp_file.path, e.what());
}
+
+ m_primary_storage.put(key, type, [&](const std::string& path) {
+ try {
+ Util::copy_file(tmp_file.path, path);
+ } catch (const Error& e) {
+ LOG("Failed to copy {} to {}: {}", tmp_file.path, path, e.what());
+ // Don't indicate failure since get from primary storage was OK.
+ }
+ return true;
+ });
+
return tmp_file.path;
}
SUITE_secondary_file_SETUP() {
unset CCACHE_NODIRECT
- export CCACHE_SECONDARY_STORAGE="file://$PWD/secondary"
+ export CCACHE_SECONDARY_STORAGE="file:$PWD/secondary"
generate_code 1 test.c
}
$CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 2
expect_stat 'cache miss' 1
- expect_stat 'files in cache' 0
- expect_stat 'files in cache' 0
+ expect_stat 'files in cache' 2 # fetched from secondary
expect_file_count 3 '*' secondary # CACHEDIR.TAG + result + manifest
# -------------------------------------------------------------------------
$CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 1
expect_stat 'cache miss' 1
- expect_stat 'files in cache' 0
+ expect_stat 'files in cache' 2 # fetched from secondary
expect_file_count 3 '*' secondary # CACHEDIR.TAG + result + manifest
expect_file_count 3 '*' secondary_2 # CACHEDIR.TAG + result + manifest
+ $CCACHE -C >/dev/null
+ expect_stat 'files in cache' 0
+
rm -r secondary/??
expect_file_count 1 '*' secondary # CACHEDIR.TAG
$CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 2
expect_stat 'cache miss' 1
- expect_stat 'files in cache' 0
+ expect_stat 'files in cache' 2 # fetched from secondary_2
expect_file_count 1 '*' secondary # CACHEDIR.TAG
expect_file_count 3 '*' secondary_2 # CACHEDIR.TAG + result + manifest
$CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 1
expect_stat 'cache miss' 1
- expect_stat 'files in cache' 0
+ expect_stat 'files in cache' 2 # fetched from secondary
expect_file_count 3 '*' secondary # CACHEDIR.TAG + result + manifest
echo 'int x;' >> test.c
$CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 1
expect_stat 'cache miss' 2
- expect_stat 'files in cache' 2
+ expect_stat 'files in cache' 4
expect_file_count 3 '*' secondary # CACHEDIR.TAG + result + manifest
# -------------------------------------------------------------------------
$CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 2
expect_stat 'cache miss' 1
- expect_stat 'files in cache' 0
- expect_stat 'files in cache' 0
+ expect_stat 'files in cache' 2 # fetched from secondary
expect_file_count 2 '*' secondary # result + manifest
# -------------------------------------------------------------------------
$CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 2
expect_stat 'cache miss' 1
- expect_stat 'files in cache' 0
- expect_stat 'files in cache' 0
+ expect_stat 'files in cache' 2 # fetched from secondary
expect_file_count 2 '*' secondary # result + manifest
fi
}
$CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 2
expect_stat 'cache miss' 1
- expect_stat 'files in cache' 0
+ expect_stat 'files in cache' 2 # fetched from secondary
expect_number_of_redis_cache_entries 2 "$redis_url" # result + manifest
# -------------------------------------------------------------------------
$CCACHE_COMPILE -c test.c
expect_stat 'cache hit (direct)' 2
expect_stat 'cache miss' 1
- expect_stat 'files in cache' 0
+ expect_stat 'files in cache' 2 # fetched from secondary
expect_number_of_redis_cache_entries 2 "$redis_url" # result + manifest
}