Browse Source

cmake: Fix '-E copy foo .' to avoid clobbering file

Backport KWSys commit 92334e7670 (SystemTools: CopyFileAlways: avoid
copying file over self, 2019-03-25) to the CMake 3.14 release branch.

Fixes: #19075
Brad King 6 years ago
parent
commit
ce180cf810
1 changed files with 4 additions and 4 deletions
  1. 4 4
      Source/kwsys/SystemTools.cxx

+ 4 - 4
Source/kwsys/SystemTools.cxx

@@ -2307,10 +2307,6 @@ static bool CloneFileContent(const std::string& source,
 bool SystemTools::CopyFileAlways(const std::string& source,
                                  const std::string& destination)
 {
-  // If files are the same do not copy
-  if (SystemTools::SameFile(source, destination)) {
-    return true;
-  }
   mode_t perm = 0;
   bool perms = SystemTools::GetPermissions(source, perm);
   std::string real_destination = destination;
@@ -2331,6 +2327,10 @@ bool SystemTools::CopyFileAlways(const std::string& source,
     } else {
       destination_dir = SystemTools::GetFilenamePath(destination);
     }
+    // If files are the same do not copy
+    if (SystemTools::SameFile(source, real_destination)) {
+      return true;
+    }
 
     // Create destination directory