void
Context::unlink_pending_tmp_files_signal_safe()
{
- for (const std::string& path : m_pending_tmp_files) {
+ for (auto it = m_pending_tmp_files.rbegin(); it != m_pending_tmp_files.rend();
+ ++it) {
// Don't call Util::unlink_tmp since its log calls aren't signal safe.
- unlink(path.c_str());
+ unlink(it->c_str());
}
// Don't clear m_pending_tmp_files since this method must be signal safe.
}
{
SignalHandlerBlocker signal_handler_blocker;
- for (const std::string& path : m_pending_tmp_files) {
- Util::unlink_tmp(path, Util::UnlinkLog::ignore_failure);
+ for (auto it = m_pending_tmp_files.rbegin(); it != m_pending_tmp_files.rend();
+ ++it) {
+ Util::unlink_tmp(*it, Util::UnlinkLog::ignore_failure);
}
m_pending_tmp_files.clear();
}
TemporaryFile tmp_stdout(
FMT("{}/tmp.cpp_stdout", ctx.config.temporary_dir()));
- stdout_path = tmp_stdout.path;
+ ctx.register_pending_tmp_file(tmp_stdout.path);
+
+ // 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(tmp_stdout.path, stdout_path);
ctx.register_pending_tmp_file(stdout_path);
TemporaryFile tmp_stderr(
if (ctx.args_info.direct_i_file) {
ctx.i_tmpfile = ctx.args_info.input_file;
} else {
- // i_tmpfile needs the proper cpp_extension for the compiler to do its
- // thing correctly
- ctx.i_tmpfile = FMT("{}.{}", stdout_path, ctx.config.cpp_extension());
- Util::rename(stdout_path, ctx.i_tmpfile);
- ctx.register_pending_tmp_file(ctx.i_tmpfile);
+ ctx.i_tmpfile = stdout_path;
}
if (!ctx.config.run_second_cpp()) {