From 128109ebb7ffd2a2168677cae42d0e0200f0dbd7 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 27 Mar 2019 21:46:49 +0100 Subject: [PATCH] Mark the manifest file as used on direct cache hit Fixes #367. --- doc/NEWS.adoc | 4 ++++ src/ccache.c | 2 +- test/run | 9 +++++++++ test/suites/direct.bash | 4 ++++ 4 files changed, 18 insertions(+), 1 deletion(-) diff --git a/doc/NEWS.adoc b/doc/NEWS.adoc index cea25ef9c..46f618dc9 100644 --- a/doc/NEWS.adoc +++ b/doc/NEWS.adoc @@ -27,6 +27,10 @@ Changes * Fixed a bug in the “depend mode” where a manifest hash only could be associated with one set of header dependencies. +* Manifest files did not get marked as used on direct cache hits, so the LRU + cache cleanup would incorrectly remove them eventually. This has now been + fixed. + ccache 3.6 ---------- diff --git a/src/ccache.c b/src/ccache.c index d0c378548..2a04ce743 100644 --- a/src/ccache.c +++ b/src/ccache.c @@ -1303,7 +1303,6 @@ update_manifest_file(void) } if (manifest_put(manifest_path, cached_obj_hash, included_files)) { cc_log("Added object file hash to %s", manifest_path); - update_mtime(manifest_path); if (x_stat(manifest_path, &st) == 0) { stats_update_size(file_size(&st) - old_size, old_size == 0 ? 1 : 0); } @@ -2137,6 +2136,7 @@ calculate_object_hash(struct args *args, struct hash *hash, int direct_mode) object_hash = manifest_get(conf, manifest_path); if (object_hash) { cc_log("Got object file hash from manifest"); + update_mtime(manifest_path); } else { cc_log("Did not find object file hash in manifest"); } diff --git a/test/run b/test/run index fa6073362..b4a96b471 100755 --- a/test/run +++ b/test/run @@ -197,6 +197,15 @@ expect_file_count() { fi } +# Verify that $1 is newer than (or same age as) $2. +expect_file_newer_than() { + local newer_file=$1 + local older_file=$2 + if [ "$newer_file" -ot "$older_file" ]; then + test_failed "$newer_file is older than $older_file" + fi +} + run_suite() { local suite_name=$1 diff --git a/test/suites/direct.bash b/test/suites/direct.bash index f3025b139..643471c18 100644 --- a/test/suites/direct.bash +++ b/test/suites/direct.bash @@ -36,12 +36,16 @@ SUITE_direct() { expect_stat 'files in cache' 2 # .o + .manifest expect_equal_object_files reference_test.o test.o + manifest_file=$(find $CCACHE_DIR -name '*.manifest') + backdate $manifest_file + $CCACHE_COMPILE -c test.c expect_stat 'cache hit (direct)' 1 expect_stat 'cache hit (preprocessed)' 0 expect_stat 'cache miss' 1 expect_stat 'files in cache' 2 expect_equal_object_files reference_test.o test.o + expect_file_newer_than $manifest_file test.c # ------------------------------------------------------------------------- TEST "Corrupt manifest file" -- 2.47.2