From: MizuhaHimuraki Date: Mon, 2 Dec 2019 20:54:22 +0000 (+0800) Subject: Store mtime/ctime as -1 if sloppy_file_stat is not set (#495) X-Git-Tag: v4.0~696 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=947030fd9a0d635651bddf538a4b40eb69c05e2d;p=thirdparty%2Fccache.git Store mtime/ctime as -1 if sloppy_file_stat is not set (#495) As discussed in #493. (cherry picked from commit 6341a2abd47eb43123ce9fc92716d9768300795e) --- diff --git a/src/ccache.cpp b/src/ccache.cpp index 81f738113..3cda1e4d6 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1218,9 +1218,13 @@ update_manifest_file(void) auto old_st = Stat::stat(manifest_path); + bool save_timestamp = (g_config.sloppiness() & SLOPPY_FILE_STAT_MATCHES) + || output_is_precompiled_header; + MTR_BEGIN("manifest", "manifest_put"); cc_log("Adding result name to %s", manifest_path); - if (!manifest_put(manifest_path, *cached_result_name, g_included_files)) { + if (!manifest_put( + manifest_path, *cached_result_name, g_included_files, save_timestamp)) { cc_log("Failed to add result name to %s", manifest_path); } else { auto st = Stat::stat(manifest_path, Stat::OnError::log); diff --git a/src/manifest.cpp b/src/manifest.cpp index 1c88cb739..e634d8615 100644 --- a/src/manifest.cpp +++ b/src/manifest.cpp @@ -173,7 +173,8 @@ struct ManifestData void add_result_entry( const struct digest& result_digest, - const std::unordered_map& included_files) + const std::unordered_map& included_files, + bool save_timestamp) { std::unordered_map mf_files; for (uint32_t i = 0; i < files.size(); ++i) { @@ -187,8 +188,8 @@ struct ManifestData std::vector file_info_indexes; for (const auto& item : included_files) { - file_info_indexes.push_back( - get_file_info_index(item.first, item.second, mf_files, mf_file_infos)); + file_info_indexes.push_back(get_file_info_index( + item.first, item.second, mf_files, mf_file_infos, save_timestamp)); } results.push_back(ResultEntry{std::move(file_info_indexes), result_digest}); @@ -200,7 +201,8 @@ private: const std::string& path, const digest& digest, const std::unordered_map& mf_files, - const std::unordered_map& mf_file_infos) + const std::unordered_map& mf_file_infos, + bool save_timestamp) { struct FileInfo fi; @@ -220,11 +222,17 @@ private: // // file_stat.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. auto file_stat = Stat::stat(path, Stat::OnError::log); if (file_stat) { - if (time_of_compilation - > std::max(file_stat.mtime(), file_stat.ctime())) { + if (save_timestamp + && time_of_compilation + > std::max(file_stat.mtime(), file_stat.ctime())) { fi.mtime = file_stat.mtime(); fi.ctime = file_stat.ctime(); } else { @@ -494,7 +502,8 @@ manifest_get(const Config& config, const std::string& path) bool manifest_put(const std::string& path, const struct digest& result_name, - const std::unordered_map& included_files) + const std::unordered_map& included_files, + bool save_timestamp) { // We don't bother to acquire a lock when writing the manifest to disk. A // race between two processes will only result in one lost entry, which is @@ -536,7 +545,7 @@ manifest_put(const std::string& path, mf = std::make_unique(); } - mf->add_result_entry(result_name, included_files); + mf->add_result_entry(result_name, included_files, save_timestamp); try { write_manifest(path, *mf); diff --git a/src/manifest.hpp b/src/manifest.hpp index 9822c45e1..62c3f3975 100644 --- a/src/manifest.hpp +++ b/src/manifest.hpp @@ -30,8 +30,8 @@ extern const uint8_t k_manifest_magic[4]; extern const uint8_t k_manifest_version; struct digest* manifest_get(const Config& config, const std::string& path); -bool -manifest_put(const std::string& path, - const struct digest& result_name, - const std::unordered_map& included_files); +bool manifest_put(const std::string& path, + const struct digest& result_name, + const std::unordered_map& included_files, + bool save_timestamp); bool manifest_dump(const std::string& path, FILE* stream);