From: Thomas Otto Date: Sat, 25 Jan 2020 09:44:12 +0000 (+0100) Subject: Context: move (cached_)result_name/result_path X-Git-Tag: v4.0~613^2~13 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6a4e0f88b483727ce58a1ff01dd39c47e03e14d4;p=thirdparty%2Fccache.git Context: move (cached_)result_name/result_path Also convert result_path to std::string. --- diff --git a/src/Context.cpp b/src/Context.cpp index cf670878f..699bb2308 100644 --- a/src/Context.cpp +++ b/src/Context.cpp @@ -30,4 +30,6 @@ Context::Context() Context::~Context() { args_free(orig_args); + + free(result_name); } diff --git a/src/Context.hpp b/src/Context.hpp index 15c869440..1e7727f0e 100644 --- a/src/Context.hpp +++ b/src/Context.hpp @@ -25,6 +25,7 @@ #include "NonCopyable.hpp" struct args; +struct digest; struct Context : NonCopyable { @@ -46,4 +47,12 @@ struct Context : NonCopyable // The original argument list. struct args* orig_args = nullptr; + + // Name (represented as a struct digest) of the file containing the cached + // result. + struct digest* result_name = nullptr; + + // Full path to the file containing the result + // (cachedir/a/b/cdef[...]-size.result). + std::string result_path; }; diff --git a/src/ccache.cpp b/src/ccache.cpp index 3b01c1875..8f9cbe998 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1053,7 +1053,7 @@ update_manifest_file(Context& ctx) cc_log("Adding result name to %s", manifest_path); if (!manifest_put(ctx.config, manifest_path, - *cached_result_name, + *ctx.result_name, g_included_files, save_timestamp)) { cc_log("Failed to add result name to %s", manifest_path); @@ -1072,13 +1072,11 @@ update_cached_result_globals(Context& ctx, struct digest* result_name) { char result_name_string[DIGEST_STRING_BUFFER_SIZE]; digest_as_string(result_name, result_name_string); - cached_result_name = result_name; - cached_result_path = - x_strdup(Util::get_path_in_cache(ctx.config.cache_dir(), - ctx.config.cache_dir_levels(), - result_name_string, - ".result") - .c_str()); + ctx.result_name = result_name; + ctx.result_path = Util::get_path_in_cache(ctx.config.cache_dir(), + ctx.config.cache_dir_levels(), + result_name_string, + ".result"); ctx.stats_file = fmt::format("{}/{}/stats", ctx.config.cache_dir(), result_name_string[0]); } @@ -1340,12 +1338,12 @@ to_cache(Context& ctx, result_file_map.emplace(FileType::dwarf_object, ctx.args_info.output_dwo); } - auto orig_dest_stat = Stat::stat(cached_result_path); - result_put(ctx, cached_result_path, result_file_map); + auto orig_dest_stat = Stat::stat(ctx.result_path); + result_put(ctx, ctx.result_path, result_file_map); - cc_log("Stored in cache: %s", cached_result_path); + cc_log("Stored in cache: %s", ctx.result_path.c_str()); - auto new_dest_stat = Stat::stat(cached_result_path, Stat::OnError::log); + auto new_dest_stat = Stat::stat(ctx.result_path, Stat::OnError::log); if (!new_dest_stat) { stats_update(STATS_ERROR); failed(); @@ -2079,7 +2077,7 @@ from_cache(Context& ctx, if (ctx.args_info.generating_diagnostics) { result_file_map.emplace(FileType::diagnostic, ctx.args_info.output_dia); } - bool ok = result_get(ctx, cached_result_path, result_file_map); + bool ok = result_get(ctx, ctx.result_path, result_file_map); if (!ok) { cc_log("Failed to get result from cache"); tmp_unlink(tmp_stderr); @@ -3529,8 +3527,6 @@ void cc_reset() { free_and_nullify(included_pch_file); - free_and_nullify(cached_result_name); - free_and_nullify(cached_result_path); free_and_nullify(manifest_path); time_of_compilation = 0; for (size_t i = 0; i < ignore_headers_len; i++) { diff --git a/src/legacy_globals.cpp b/src/legacy_globals.cpp index 51088f4a2..aba2231d1 100644 --- a/src/legacy_globals.cpp +++ b/src/legacy_globals.cpp @@ -18,14 +18,6 @@ #include "legacy_globals.hpp" -// Name (represented as a struct digest) of the file containing the cached -// result. -struct digest* cached_result_name; - -// Full path to the file containing the result -// (cachedir/a/b/cdef[...]-size.result). -char* cached_result_path; - // Full path to the file containing the manifest // (cachedir/a/b/cdef[...]-size.manifest). char* manifest_path; diff --git a/src/legacy_globals.hpp b/src/legacy_globals.hpp index bc51d2249..0ee048d47 100644 --- a/src/legacy_globals.hpp +++ b/src/legacy_globals.hpp @@ -30,10 +30,6 @@ extern unsigned lock_staleness_limit; -extern struct digest* cached_result_name; - -extern char* cached_result_path; - extern char* manifest_path; extern time_t time_of_compilation;