]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Remove corrupt manifest files so that they won't block direct mode hits
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 14 Dec 2010 20:11:36 +0000 (21:11 +0100)
committerJoel Rosdahl <joel@rosdahl.net>
Tue, 14 Dec 2010 20:11:36 +0000 (21:11 +0100)
manifest.c
test.sh

index f9c4dd0f4cde94d768759801efc07cbbdbb94715..fcc163d659624601fea536171e9558940c3c14e6 100644 (file)
@@ -581,7 +581,6 @@ manifest_put(const char *manifest_path, struct file_hash *object_hash,
        int ret = 0;
        int fd1;
        int fd2;
-       gzFile f1 = NULL;
        gzFile f2 = NULL;
        struct manifest *mf = NULL;
        char *tmp_file = NULL;
@@ -597,26 +596,21 @@ manifest_put(const char *manifest_path, struct file_hash *object_hash,
                /* New file. */
                mf = create_empty_manifest();
        } else {
-               f1 = gzdopen(fd1, "rb");
+               gzFile f1 = gzdopen(fd1, "rb");
                if (!f1) {
                        cc_log("Failed to gzdopen manifest file");
                        close(fd1);
                        goto out;
                }
                mf = read_manifest(f1);
+               gzclose(f1);
                if (!mf) {
-                       cc_log("Failed to read manifest file");
-                       gzclose(f1);
-                       goto out;
+                       cc_log("Failed to read manifest file; deleting it");
+                       x_unlink(manifest_path);
+                       mf = create_empty_manifest();
                }
        }
 
-       if (f1) {
-               gzclose(f1);
-       } else {
-               close(fd1);
-       }
-
        if (mf->n_objects > MAX_MANIFEST_ENTRIES) {
                /*
                 * Normally, there shouldn't be many object entries in the manifest since
diff --git a/test.sh b/test.sh
index 0558e4a7b2d5313b577da8990a17f53bd8fefddc..7bdf39bc3b7bf2b7db141f52c9f0af33aadb8e1b 100755 (executable)
--- a/test.sh
+++ b/test.sh
@@ -576,6 +576,22 @@ EOF
     checkstat 'cache hit (preprocessed)' 0
     checkstat 'cache miss' 0
 
+    ##################################################################
+    # Check that corrupt manifest files are handled and rewritten.
+    testname="corrupt manifest file"
+    $CCACHE -z >/dev/null
+    manifest_file=`find $CCACHE_DIR -name '*.manifest'`
+    rm $manifest_file
+    touch $manifest_file
+    $CCACHE $COMPILER -c test.c
+    checkstat 'cache hit (direct)' 0
+    checkstat 'cache hit (preprocessed)' 1
+    checkstat 'cache miss' 0
+    $CCACHE $COMPILER -c test.c
+    checkstat 'cache hit (direct)' 1
+    checkstat 'cache hit (preprocessed)' 1
+    checkstat 'cache miss' 0
+
     ##################################################################
     # Compiling with CCACHE_NODIRECT set should generate a preprocessed hit.
     testname="preprocessed hit"