From 62bb8a77a590c705b73ea80783d2d2693e70cfa8 Mon Sep 17 00:00:00 2001 From: Alex Turbov Date: Mon, 1 Jul 2024 01:52:47 +0400 Subject: [PATCH] cmMakefile: Teach ConfigureFile to move the temp file instead of copying it In the variables substitution mode `cmMakefile::ConfigureFile` was copy file and then remove temporary rendered file. With updated signature of `MoveFileIfDifferent` it can be used instead of `CopyFileIfDifferent`. --- Source/cmMakefile.cxx | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx index d496d36cc5..2803279beb 100644 --- a/Source/cmMakefile.cxx +++ b/Source/cmMakefile.cxx @@ -4076,15 +4076,23 @@ int cmMakefile::ConfigureFile(const std::string& infile, } if (copyonly) { - if (!cmSystemTools::CopyFileIfDifferent(sinfile, soutfile)) { - this->IssueMessage(MessageType::FATAL_ERROR, - cmSystemTools::GetLastSystemError()); - return 0; - } - if (!cmSystemTools::SetPermissions(soutfile, permissions)) { - this->IssueMessage(MessageType::FATAL_ERROR, - cmSystemTools::GetLastSystemError()); + const auto copy_status = + cmSystemTools::CopyFileIfDifferent(sinfile, soutfile); + if (!copy_status) { + this->IssueMessage( + MessageType::FATAL_ERROR, + cmStrCat("Fail to copy ", + copy_status.Path == cmsys::SystemTools::CopyStatus::SourcePath + ? "source" + : "destination", + "file: ", copy_status.GetString())); res = 0; + } else { + const auto status = cmSystemTools::SetPermissions(soutfile, permissions); + if (!status) { + this->IssueMessage(MessageType::FATAL_ERROR, status.GetString()); + res = 0; + } } return res; } @@ -4135,18 +4143,18 @@ int cmMakefile::ConfigureFile(const std::string& infile, // close the files before attempting to copy fin.close(); fout.close(); - if (!cmSystemTools::CopyFileIfDifferent(tempOutputFile, soutfile)) { - this->IssueMessage(MessageType::FATAL_ERROR, - cmSystemTools::GetLastSystemError()); + + auto status = cmSystemTools::MoveFileIfDifferent(tempOutputFile, soutfile); + if (!status) { + this->IssueMessage(MessageType::FATAL_ERROR, status.GetString()); res = 0; } else { - if (!cmSystemTools::SetPermissions(soutfile, permissions)) { - this->IssueMessage(MessageType::FATAL_ERROR, - cmSystemTools::GetLastSystemError()); + status = cmSystemTools::SetPermissions(soutfile, permissions); + if (!status) { + this->IssueMessage(MessageType::FATAL_ERROR, status.GetString()); res = 0; } } - cmSystemTools::RemoveFile(tempOutputFile); return res; }