Ver Fonte

cmSystemTools: Revise MoveFileIfDifferent to return cmsys::Status

Help callers recover errors without relying on global state.
Alex Turbov há 1 ano atrás
pai
commit
dc38f81237
2 ficheiros alterados com 8 adições e 6 exclusões
  1. 6 4
      Source/cmSystemTools.cxx
  2. 2 2
      Source/cmSystemTools.h

+ 6 - 4
Source/cmSystemTools.cxx

@@ -1319,16 +1319,18 @@ cmSystemTools::RenameResult cmSystemTools::RenameFile(
 #endif
 }
 
-void cmSystemTools::MoveFileIfDifferent(const std::string& source,
-                                        const std::string& destination)
+cmsys::Status cmSystemTools::MoveFileIfDifferent(
+  const std::string& source, const std::string& destination)
 {
+  cmsys::Status res = {};
   if (FilesDiffer(source, destination)) {
     if (RenameFile(source, destination)) {
-      return;
+      return res;
     }
-    CopyFileAlways(source, destination);
+    res = CopyFileAlways(source, destination);
   }
   RemoveFile(source);
+  return res;
 }
 
 void cmSystemTools::Glob(const std::string& directory,

+ 2 - 2
Source/cmSystemTools.h

@@ -211,8 +211,8 @@ public:
                                  std::string* err = nullptr);
 
   //! Rename a file if contents are different, delete the source otherwise
-  static void MoveFileIfDifferent(const std::string& source,
-                                  const std::string& destination);
+  static cmsys::Status MoveFileIfDifferent(const std::string& source,
+                                           const std::string& destination);
 
   /**
    * Run a single executable command