summaryrefslogtreecommitdiffstats
path: root/Source/cmMakefile.cxx
diff options
context:
space:
mode:
authorAlex Turbov <i.zaufi@gmail.com>2024-06-30 21:52:47 (GMT)
committerBrad King <brad.king@kitware.com>2024-07-18 14:29:47 (GMT)
commit62bb8a77a590c705b73ea80783d2d2693e70cfa8 (patch)
treeeb9ea3568cba3740ecede76b45b229c4ab06c386 /Source/cmMakefile.cxx
parentdc38f812378b5feedf29f9ea23ba764f62ea3b04 (diff)
downloadCMake-62bb8a77a590c705b73ea80783d2d2693e70cfa8.zip
CMake-62bb8a77a590c705b73ea80783d2d2693e70cfa8.tar.gz
CMake-62bb8a77a590c705b73ea80783d2d2693e70cfa8.tar.bz2
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`.
Diffstat (limited to 'Source/cmMakefile.cxx')
-rw-r--r--Source/cmMakefile.cxx38
1 files changed, 23 insertions, 15 deletions
diff --git a/Source/cmMakefile.cxx b/Source/cmMakefile.cxx
index d496d36..2803279 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;
}