Procházet zdrojové kódy

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`.
Alex Turbov před 1 rokem
rodič
revize
62bb8a77a5
1 změnil soubory, kde provedl 23 přidání a 15 odebrání
  1. 23 15
      Source/cmMakefile.cxx

+ 23 - 15
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;
 }