summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMizuhaHimuraki <mocha.java.cchip@gmail.com>2019-12-03 04:54:22 +0800
committerJoel Rosdahl <joel@rosdahl.net>2019-12-02 21:54:22 +0100
commit6341a2abd47eb43123ce9fc92716d9768300795e (patch)
tree55972b9770a1df014ebc40409c4abc4e3d21da6c
parent1a4929bfd73e63ebd1b369ee116f9c57f1931824 (diff)
downloadccache-6341a2abd47eb43123ce9fc92716d9768300795e.tar.gz
Store mtime/ctime as -1 if sloppy_file_stat is not set (#495)
As discussed in #493.
-rw-r--r--src/ccache.c7
-rw-r--r--src/manifest.c25
-rw-r--r--src/manifest.h2
3 files changed, 24 insertions, 10 deletions
diff --git a/src/ccache.c b/src/ccache.c
index dbfd8213..a8da3419 100644
--- a/src/ccache.c
+++ b/src/ccache.c
@@ -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(
diff --git a/src/manifest.c b/src/manifest.c
index 603d85bb..9f46e66f 100644
--- a/src/manifest.c
+++ b/src/manifest.c
@@ -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;
diff --git a/src/manifest.h b/src/manifest.h
index e116c349..8878384e 100644
--- a/src/manifest.h
+++ b/src/manifest.h
@@ -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