Browse Source

cmSystemTools: copy file member functions accept std::string params

Cleaned up `c_str()`s.
`cmSystemTools::CopyFileIfDifferent()` removed as redundant.
Vitaly Stakhovsky 6 years ago
parent
commit
c31b6e616d

+ 1 - 2
Source/CPack/IFW/cmCPackIFWInstaller.cxx

@@ -288,8 +288,7 @@ protected:
       content = cmSystemTools::TrimWhitespace(content);
       std::string source = this->basePath + "/" + content;
       std::string destination = this->path + "/" + content;
-      if (!cmSystemTools::CopyFileIfDifferent(source.data(),
-                                              destination.data())) {
+      if (!cmSystemTools::CopyFileIfDifferent(source, destination)) {
         this->hasErrors = true;
       }
     }

+ 1 - 2
Source/CPack/cmCPackDragNDropGenerator.cxx

@@ -212,8 +212,7 @@ int cmCPackDragNDropGenerator::PackageFiles()
 bool cmCPackDragNDropGenerator::CopyFile(std::ostringstream& source,
                                          std::ostringstream& target)
 {
-  if (!cmSystemTools::CopyFileIfDifferent(source.str().c_str(),
-                                          target.str().c_str())) {
+  if (!cmSystemTools::CopyFileIfDifferent(source.str(), target.str())) {
     cmCPackLogger(cmCPackLog::LOG_ERROR,
                   "Error copying " << source.str() << " to " << target.str()
                                    << std::endl);

+ 2 - 4
Source/CPack/cmCPackGenerator.cxx

@@ -392,8 +392,7 @@ int cmCPackGenerator::InstallProjectViaInstalledDirectories(
                                       std::move(inFileRelative));
         }
         /* If it is not a symlink then do a plain copy */
-        else if (!(cmSystemTools::CopyFileIfDifferent(inFile.c_str(),
-                                                      filePath.c_str()) &&
+        else if (!(cmSystemTools::CopyFileIfDifferent(inFile, filePath) &&
                    cmSystemTools::CopyFileTime(inFile.c_str(),
                                                filePath.c_str()))) {
           cmCPackLogger(cmCPackLog::LOG_ERROR,
@@ -1077,8 +1076,7 @@ int cmCPackGenerator::DoPackage()
                     << (tempPackageFileName ? tempPackageFileName : "(NULL)")
                     << " to " << (packageFileName ? packageFileName : "(NULL)")
                     << std::endl);
-    if (!cmSystemTools::CopyFileIfDifferent(tempPackageFileName,
-                                            packageFileName)) {
+    if (!cmSystemTools::CopyFileIfDifferent(pkgFileName, tmpPF)) {
       cmCPackLogger(
         cmCPackLog::LOG_ERROR,
         "Problem copying the package: "

+ 1 - 2
Source/cmFileCommand.cxx

@@ -3759,8 +3759,7 @@ bool cmFileCommand::HandleCreateLinkCommand(
 
   // Check if copy-on-error is enabled in the arguments.
   if (!completed && copyOnErrorArg.IsEnabled()) {
-    completed =
-      cmSystemTools::cmCopyFile(fileName.c_str(), newFileName.c_str());
+    completed = cmSystemTools::cmCopyFile(fileName, newFileName);
     if (!completed) {
       result = "Copy failed: " + cmSystemTools::GetLastSystemError();
     }

+ 2 - 3
Source/cmGlobalVisualStudioGenerator.cxx

@@ -262,9 +262,8 @@ void cmGlobalVisualStudioGenerator::ConfigureCMakeVisualStudioMacros()
     // purposes but newer versions distributed with CMake will replace
     // older versions in user directories.
     int res;
-    if (!cmSystemTools::FileTimeCompare(src.c_str(), dst.c_str(), &res) ||
-        res > 0) {
-      if (!cmSystemTools::CopyFileAlways(src.c_str(), dst.c_str())) {
+    if (!cmSystemTools::FileTimeCompare(src, dst, &res) || res > 0) {
+      if (!cmSystemTools::CopyFileAlways(src, dst)) {
         std::ostringstream oss;
         oss << "Could not copy from: " << src << std::endl;
         oss << "                 to: " << dst << std::endl;

+ 2 - 4
Source/cmMakefile.cxx

@@ -3750,8 +3750,7 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
   }
 
   if (copyonly) {
-    if (!cmSystemTools::CopyFileIfDifferent(sinfile.c_str(),
-                                            soutfile.c_str())) {
+    if (!cmSystemTools::CopyFileIfDifferent(sinfile, soutfile)) {
       return 0;
     }
   } else {
@@ -3802,8 +3801,7 @@ int cmMakefile::ConfigureFile(const char* infile, const char* outfile,
     // close the files before attempting to copy
     fin.close();
     fout.close();
-    if (!cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(),
-                                            soutfile.c_str())) {
+    if (!cmSystemTools::CopyFileIfDifferent(tempOutputFile, soutfile)) {
       res = 0;
     } else {
       cmSystemTools::SetPermissions(soutfile, perm);

+ 2 - 7
Source/cmSystemTools.cxx

@@ -940,17 +940,12 @@ std::string cmSystemTools::FileExistsInParentDirectories(const char* fname,
   return "";
 }
 
-bool cmSystemTools::cmCopyFile(const char* source, const char* destination)
+bool cmSystemTools::cmCopyFile(const std::string& source,
+                               const std::string& destination)
 {
   return Superclass::CopyFileAlways(source, destination);
 }
 
-bool cmSystemTools::CopyFileIfDifferent(const char* source,
-                                        const char* destination)
-{
-  return Superclass::CopyFileIfDifferent(source, destination);
-}
-
 #ifdef _WIN32
 cmSystemTools::WindowsFileRetry cmSystemTools::GetWindowsFileRetry()
 {

+ 2 - 2
Source/cmSystemTools.h

@@ -179,8 +179,8 @@ public:
                          std::vector<std::string>& files, int type = 0);
 
   ///! Copy a file.
-  static bool cmCopyFile(const char* source, const char* destination);
-  static bool CopyFileIfDifferent(const char* source, const char* destination);
+  static bool cmCopyFile(const std::string& source,
+                         const std::string& destination);
 
   /** Rename a file or directory within a single disk volume (atomic
       if possible).  */

+ 1 - 1
Source/cmUseMangledMesaCommand.cxx

@@ -100,6 +100,6 @@ void cmUseMangledMesaCommand::CopyAndFullPathMesaHeader(const char* source,
   // close the files before attempting to copy
   fin.close();
   fout.close();
-  cmSystemTools::CopyFileIfDifferent(tempOutputFile.c_str(), outFile.c_str());
+  cmSystemTools::CopyFileIfDifferent(tempOutputFile, outFile);
   cmSystemTools::RemoveFile(tempOutputFile);
 }

+ 1 - 1
Source/cmake.cxx

@@ -2358,7 +2358,7 @@ int cmake::GetSystemInformation(std::vector<std::string>& args)
   outFile += "/CMakeLists.txt";
 
   // Copy file
-  if (!cmSystemTools::cmCopyFile(inFile.c_str(), outFile.c_str())) {
+  if (!cmSystemTools::cmCopyFile(inFile, outFile)) {
     std::cerr << "Error copying file \"" << inFile << "\" to \"" << outFile
               << "\".\n";
     return 1;

+ 3 - 5
Source/cmcmd.cxx

@@ -482,8 +482,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
       // If error occurs we want to continue copying next files.
       bool return_value = false;
       for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) {
-        if (!cmSystemTools::cmCopyFile(args[cc].c_str(),
-                                       args.back().c_str())) {
+        if (!cmSystemTools::cmCopyFile(args[cc], args.back())) {
           std::cerr << "Error copying file \"" << args[cc] << "\" to \""
                     << args.back() << "\".\n";
           return_value = true;
@@ -505,8 +504,7 @@ int cmcmd::ExecuteCMakeCommand(std::vector<std::string>& args)
       // If error occurs we want to continue copying next files.
       bool return_value = false;
       for (std::string::size_type cc = 2; cc < args.size() - 1; cc++) {
-        if (!cmSystemTools::CopyFileIfDifferent(args[cc].c_str(),
-                                                args.back().c_str())) {
+        if (!cmSystemTools::CopyFileIfDifferent(args[cc], args.back())) {
           std::cerr << "Error copying file (if different) from \"" << args[cc]
                     << "\" to \"" << args.back() << "\".\n";
           return_value = true;
@@ -1304,7 +1302,7 @@ bool cmcmd::SymlinkInternal(std::string const& file, std::string const& link)
     cmSystemTools::RemoveFile(link);
   }
 #if defined(_WIN32) && !defined(__CYGWIN__)
-  return cmSystemTools::CopyFileAlways(file.c_str(), link.c_str());
+  return cmSystemTools::CopyFileAlways(file, link);
 #else
   std::string linktext = cmSystemTools::GetFilenameName(file);
   return cmSystemTools::CreateSymlink(linktext, link);