[Cmake-commits] [cmake-commits] king committed cmFileCommand.cxx 1.118 1.119 cmFileCommand.h 1.42 1.43

cmake-commits at cmake.org cmake-commits at cmake.org
Wed Apr 15 09:58:15 EDT 2009


Update of /cvsroot/CMake/CMake/Source
In directory public:/mounts/ram/cvs-serv17511/Source

Modified Files:
	cmFileCommand.cxx cmFileCommand.h 
Log Message:
ENH: Create file(RENAME) command mode

This creates command "file(RENAME <oldname> <newname>)" to rename a file
or directory within a single disk volume.


Index: cmFileCommand.h
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.h,v
retrieving revision 1.42
retrieving revision 1.43
diff -C 2 -d -r1.42 -r1.43
*** cmFileCommand.h	7 Jan 2009 19:16:35 -0000	1.42
--- cmFileCommand.h	15 Apr 2009 13:58:13 -0000	1.43
***************
*** 79,82 ****
--- 79,83 ----
        "  file(GLOB_RECURSE variable [RELATIVE path] \n"
        "       [FOLLOW_SYMLINKS] [globbing expressions]...)\n"
+       "  file(RENAME <oldname> <newname>)\n"
        "  file(REMOVE [file1 ...])\n"
        "  file(REMOVE_RECURSE [file1 ...])\n"
***************
*** 134,137 ****
--- 135,141 ----
        "MAKE_DIRECTORY will create the given directories, also if their parent "
        "directories don't exist yet\n"
+       "RENAME moves a file or directory within a filesystem, "
+       "replacing the destination atomically."
+       "\n"
        "REMOVE will remove the given files, also in subdirectories\n"
        "REMOVE_RECURSE will remove the given files and directories, also "
***************
*** 160,163 ****
--- 164,168 ----
  
  protected:
+   bool HandleRename(std::vector<std::string> const& args);
    bool HandleRemove(std::vector<std::string> const& args, bool recurse);
    bool HandleWriteCommand(std::vector<std::string> const& args, bool append);

Index: cmFileCommand.cxx
===================================================================
RCS file: /cvsroot/CMake/CMake/Source/cmFileCommand.cxx,v
retrieving revision 1.118
retrieving revision 1.119
diff -C 2 -d -r1.118 -r1.119
*** cmFileCommand.cxx	6 Mar 2009 14:14:57 -0000	1.118
--- cmFileCommand.cxx	15 Apr 2009 13:58:13 -0000	1.119
***************
*** 101,104 ****
--- 101,108 ----
      return this->HandleMakeDirectoryCommand(args);
      }
+   else if ( subCommand == "RENAME" )
+     {
+     return this->HandleRename(args);
+     }
    else if ( subCommand == "REMOVE" )
      {
***************
*** 2176,2179 ****
--- 2180,2222 ----
  
  //----------------------------------------------------------------------------
+ bool cmFileCommand::HandleRename(std::vector<std::string> const& args)
+ {
+   if(args.size() != 3)
+     {
+     this->SetError("given incorrect number of arguments.");
+     return false;
+     }
+ 
+   // Compute full path for old and new names.
+   std::string oldname = args[1];
+   if(!cmsys::SystemTools::FileIsFullPath(oldname.c_str()))
+     {
+     oldname = this->Makefile->GetCurrentDirectory();
+     oldname += "/" + args[1];
+     }
+   std::string newname = args[2];
+   if(!cmsys::SystemTools::FileIsFullPath(newname.c_str()))
+     {
+     newname = this->Makefile->GetCurrentDirectory();
+     newname += "/" + args[2];
+     }
+ 
+   if(!cmSystemTools::RenameFile(oldname.c_str(), newname.c_str()))
+     {
+     std::string err = cmSystemTools::GetLastSystemError();
+     cmOStringStream e;
+     e << "RENAME failed to rename\n"
+       << "  " << oldname << "\n"
+       << "to\n"
+       << "  " << newname << "\n"
+       << "because: " << err << "\n";
+     this->SetError(e.str().c_str());
+     return false;
+     }
+   return true;
+ }
+ 
+ 
+ //----------------------------------------------------------------------------
  bool cmFileCommand::HandleRemove(std::vector<std::string> const& args,
                                   bool recurse)



More information about the Cmake-commits mailing list