From: Joel Rosdahl Date: Tue, 7 Jun 2022 12:40:08 +0000 (+0200) Subject: Revert "fix: Fall back to copying temporary preprocessed output file" X-Git-Tag: v4.7~204 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=3add35074a6d9c7e64274bedca5b667c9e36367a;p=thirdparty%2Fccache.git Revert "fix: Fall back to copying temporary preprocessed output file" This reverts commit cbedccc9fa30f8958dc3e7fbdf900a952f63d5ad since the fix doesn't work. The hard link in question is used in get_result_key_from_cpp to create an alias of file that captures stdout from the preprocessor, where the alias has the correct cpp extension. It can't just be a copy since do_execute writes to the original name. See #1079. --- diff --git a/src/Result.cpp b/src/Result.cpp index b272f33c3..bc7c313d6 100644 --- a/src/Result.cpp +++ b/src/Result.cpp @@ -417,7 +417,7 @@ Result::Writer::write_raw_file_entry(const std::string& path, const auto raw_file = get_raw_file_path(m_result_path, entry_number); const auto old_stat = Stat::stat(raw_file); try { - Util::clone_hard_link_or_copy_file(m_ctx.config, path, raw_file, true); + Util::clone_hard_link_or_copy_file(m_ctx, path, raw_file, true); } catch (core::Error& e) { throw core::Error( "Failed to store {} as raw file {}: {}", path, raw_file, e.what()); diff --git a/src/ResultRetriever.cpp b/src/ResultRetriever.cpp index 430ff9667..c1c584ebc 100644 --- a/src/ResultRetriever.cpp +++ b/src/ResultRetriever.cpp @@ -117,8 +117,7 @@ ResultRetriever::on_entry_start(uint8_t entry_number, } else if (dest_path == "/dev/null") { LOG_RAW("Not writing to /dev/null"); } else if (raw_file) { - Util::clone_hard_link_or_copy_file( - m_ctx.config, *raw_file, dest_path, false); + Util::clone_hard_link_or_copy_file(m_ctx, *raw_file, dest_path, false); // Update modification timestamp to save the file from LRU cleanup (and, if // hard-linked, to make the object file newer than the source file). diff --git a/src/Util.cpp b/src/Util.cpp index bb1f145b7..b94ee1a81 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -293,14 +293,13 @@ clone_file(const std::string& src, const std::string& dest, bool via_tmp_file) } #endif // FILE_CLONING_SUPPORTED -static void -clone_hard_link_or_copy_file(const std::string& source, +void +clone_hard_link_or_copy_file(const Context& ctx, + const std::string& source, const std::string& dest, - bool try_clone, - bool try_hard_link, bool via_tmp_file) { - if (try_clone) { + if (ctx.config.file_clone()) { #ifdef FILE_CLONING_SUPPORTED LOG("Cloning {} to {}", source, dest); try { @@ -313,7 +312,7 @@ clone_hard_link_or_copy_file(const std::string& source, LOG("Not cloning {} to {} since it's unsupported", source, dest); #endif } - if (try_hard_link) { + if (ctx.config.hard_link()) { LOG("Hard linking {} to {}", source, dest); try { Util::hard_link(source, dest); @@ -333,16 +332,6 @@ clone_hard_link_or_copy_file(const std::string& source, copy_file(source, dest, via_tmp_file); } -void -clone_hard_link_or_copy_file(const Config& config, - const std::string& source, - const std::string& dest, - bool via_tmp_file) -{ - clone_hard_link_or_copy_file( - source, dest, config.file_clone(), config.hard_link(), via_tmp_file); -} - size_t common_dir_prefix_length(std::string_view dir, std::string_view path) { @@ -794,12 +783,6 @@ hard_link(const std::string& oldpath, const std::string& newpath) #endif } -void -hard_link_or_copy(const std::string& oldpath, const std::string& newpath) -{ - return clone_hard_link_or_copy_file(oldpath, newpath, false, true, false); -} - std::optional is_absolute_path_with_prefix(std::string_view path) { diff --git a/src/Util.hpp b/src/Util.hpp index 4358fca5a..bf5548440 100644 --- a/src/Util.hpp +++ b/src/Util.hpp @@ -32,7 +32,6 @@ #include #include -class Config; class Context; namespace Util { @@ -98,7 +97,7 @@ void clone_file(const std::string& src, // Clone, hard link or copy a file from `source` to `dest` depending on settings // in `ctx`. If cloning or hard linking cannot and should not be done the file // will be copied instead. Throws `core::Error` on error. -void clone_hard_link_or_copy_file(const Config& config, +void clone_hard_link_or_copy_file(const Context& ctx, const std::string& source, const std::string& dest, bool via_tmp_file = false); @@ -193,10 +192,6 @@ mode_t get_umask(); // Hard-link `oldpath` to `newpath`. Throws `core::Error` on error. void hard_link(const std::string& oldpath, const std::string& newpath); -// Hard-link `oldpath` to `newpath`, or fall back to copying if hard-linking -// doesn't work. Throws `core::Error` on error. -void hard_link_or_copy(const std::string& oldpath, const std::string& newpath); - // Write bytes in big endian order from an integer value. // // Parameters: diff --git a/src/ccache.cpp b/src/ccache.cpp index db93bc8d7..203c2893b 100644 --- a/src/ccache.cpp +++ b/src/ccache.cpp @@ -1125,7 +1125,7 @@ get_result_key_from_cpp(Context& ctx, Args& args, Hash& hash) // stdout_path needs the proper cpp_extension for the compiler to do its // thing correctly. stdout_path = FMT("{}.{}", tmp_stdout.path, ctx.config.cpp_extension()); - Util::hard_link_or_copy(tmp_stdout.path, stdout_path); + Util::hard_link(tmp_stdout.path, stdout_path); ctx.register_pending_tmp_file(stdout_path); TemporaryFile tmp_stderr(