]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Store mtime/ctime as -1 if sloppy_file_stat is not set (#495)
authorMizuhaHimuraki <mocha.java.cchip@gmail.com>
Mon, 2 Dec 2019 20:54:22 +0000 (04:54 +0800)
committerJoel Rosdahl <joel@rosdahl.net>
Mon, 2 Dec 2019 20:54:22 +0000 (21:54 +0100)
As discussed in #493.

src/ccache.c
src/manifest.c
src/manifest.h

index dbfd82134454b88a7e64e83e18d0c0f89975e681..a8da341902a4a50b0c1920b12e3e63951e56d277 100644 (file)
@@ -1386,8 +1386,13 @@ update_manifest_file(void)
                old_size = file_size(&st);
        }
 
+       bool save_timestamp =
+               (conf->sloppiness & SLOPPY_FILE_STAT_MATCHES)
+               || output_is_precompiled_header;
+
        MTR_BEGIN("manifest", "manifest_put");
-       if (manifest_put(manifest_path, cached_obj_hash, included_files)) {
+       if (manifest_put(manifest_path, cached_obj_hash, included_files,
+                        save_timestamp)) {
                cc_log("Added object file hash to %s", manifest_path);
                if (x_stat(manifest_path, &st) == 0) {
                        stats_update_size(
index 603d85bbd1864679b3d90387d1ccbf0a6e55f9e1..9f46e66fc7cb182c7e026a48fb32aa482a31f5f0 100644 (file)
@@ -493,7 +493,8 @@ get_file_hash_index(struct manifest *mf,
                     char *path,
                     struct file_hash *file_hash,
                     struct hashtable *mf_files,
-                    struct hashtable *mf_file_infos)
+                    struct hashtable *mf_file_infos,
+                    bool save_timestamp)
 {
        struct file_info fi;
        fi.index = get_include_file_index(mf, path, mf_files);
@@ -507,8 +508,13 @@ get_file_hash_index(struct manifest *mf,
        // st->ctime may be 0, so we have to check time_of_compilation against
        // MAX(mtime, ctime).
 
+       // ccache only reads mtime/ctime if sloppy_file_stat_match is setted,
+       // so mtimes/ctimes could store as a dummy value (-1) in other scenarios.
+       // This will effectively control the total number of file infos in
+       // certain scenarios, such as CI.
+
        struct stat file_stat;
-       if (stat(path, &file_stat) != -1
+       if (save_timestamp && stat(path, &file_stat) != -1
            && time_of_compilation > MAX(file_stat.st_mtime, file_stat.st_ctime)) {
                fi.mtime = file_stat.st_mtime;
                fi.ctime = file_stat.st_ctime;
@@ -531,7 +537,8 @@ get_file_hash_index(struct manifest *mf,
 
 static void
 add_file_info_indexes(uint32_t *indexes, uint32_t size,
-                      struct manifest *mf, struct hashtable *included_files)
+                      struct manifest *mf, struct hashtable *included_files,
+                      bool save_timestamp)
 {
        if (size == 0) {
                return;
@@ -549,7 +556,7 @@ add_file_info_indexes(uint32_t *indexes, uint32_t size,
                char *path = hashtable_iterator_key(iter);
                struct file_hash *file_hash = hashtable_iterator_value(iter);
                indexes[i] = get_file_hash_index(mf, path, file_hash, mf_files,
-                                                mf_file_infos);
+                                                mf_file_infos, save_timestamp);
                i++;
        } while (hashtable_iterator_advance(iter));
        assert(i == size);
@@ -561,7 +568,8 @@ add_file_info_indexes(uint32_t *indexes, uint32_t size,
 static void
 add_object_entry(struct manifest *mf,
                  struct file_hash *object_hash,
-                 struct hashtable *included_files)
+                 struct hashtable *included_files,
+                 bool save_timestamp)
 {
        uint32_t n_objs = mf->n_objects;
        mf->objects = x_realloc(mf->objects, (n_objs + 1) * sizeof(*mf->objects));
@@ -571,7 +579,8 @@ add_object_entry(struct manifest *mf,
        uint32_t n_fii = hashtable_count(included_files);
        obj->n_file_info_indexes = n_fii;
        obj->file_info_indexes = x_malloc(n_fii * sizeof(*obj->file_info_indexes));
-       add_file_info_indexes(obj->file_info_indexes, n_fii, mf, included_files);
+       add_file_info_indexes(obj->file_info_indexes, n_fii, mf, included_files,
+                             save_timestamp);
        memcpy(obj->hash.hash, object_hash->hash, mf->hash_size);
        obj->hash.size = object_hash->size;
 }
@@ -640,7 +649,7 @@ out:
 // Returns true on success, otherwise false.
 bool
 manifest_put(const char *manifest_path, struct file_hash *object_hash,
-             struct hashtable *included_files)
+             struct hashtable *included_files, bool save_timestamp)
 {
        int ret = 0;
        gzFile f2 = NULL;
@@ -707,7 +716,7 @@ manifest_put(const char *manifest_path, struct file_hash *object_hash,
                goto out;
        }
 
-       add_object_entry(mf, object_hash, included_files);
+       add_object_entry(mf, object_hash, included_files, save_timestamp);
        if (write_manifest(f2, mf)) {
                gzclose(f2);
                f2 = NULL;
index e116c3491014b2ca73edc6079e3081248ed6428a..8878384efd9b4d496f57e75672dd1c3913661484 100644 (file)
@@ -9,7 +9,7 @@
 
 struct file_hash *manifest_get(struct conf *conf, const char *manifest_path);
 bool manifest_put(const char *manifest_path, struct file_hash *object_hash,
-                  struct hashtable *included_files);
+                  struct hashtable *included_files, bool save_timestamp);
 bool manifest_dump(const char *manifest_path, FILE *stream);
 
 #endif