Salome HOME
Adaptations for Windows
[tools/libbatch.git] / src / Core / CommunicationProtocol.cxx
index 57a1d527e70a12c7c190a8e90bc8d754a7a51d51..aaee92b1c16073fb9e3e8eaef4657cc9e3cf11a8 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2007-2015  CEA/DEN, EDF R&D, OPEN CASCADE
+// Copyright (C) 2007-2019  CEA/DEN, EDF R&D, OPEN CASCADE
 //
 // Copyright (C) 2003-2007  OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN,
 // CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS
 #ifdef HAS_SSH
  #include "CommunicationProtocolSSH.hxx"
 #endif
+#ifdef HAS_RSYNC
+ #include "CommunicationProtocolRsync.hxx"
+#endif
 #include "APIInternalFailureException.hxx"
 #include "RunTimeException.hxx"
 #include "Log.hxx"
+#include "Utils.hxx"
 
 using namespace std;
 
@@ -82,6 +86,14 @@ namespace Batch {
 #else
       throw RunTimeException("Can't use SSH protocol (SSH tools were "
                              "not found on the system at compile time).");
+#endif
+    } else if (protocolType == RSYNC) {
+#ifdef HAS_RSYNC
+      static CommunicationProtocolRsync instanceRsync;
+      return instanceRsync;
+#else
+      throw RunTimeException("Can't use RSYNC protocol (RSYNC tools were "
+                             "not found on the system at compile time).");
 #endif
     } else
       throw APIInternalFailureException("Unknown communication protocol.");
@@ -111,17 +123,29 @@ namespace Batch {
 
   string CommunicationProtocol::getRemoveSubCommand(const string & path) const
   {
+#ifdef WIN32
+    return string("del /s ") + path;
+#else
     return string("rm ") + path;
+#endif
   }
 
   string CommunicationProtocol::getRemoveDirectorySubCommand(const string & path) const
   {
+#ifdef WIN32
+    return string("rd /s /q ") + path;
+#else
     return string("rm -fR ") + path;
+#endif
   }
 
   string CommunicationProtocol::getMakeDirectorySubCommand(const string & path) const
   {
+#ifdef WIN32
+    return string("md ") + path;
+#else
     return string("mkdir -p ") + path;
+#endif
   }
 
   int CommunicationProtocol::removeFile(const std::string & path,
@@ -169,7 +193,8 @@ namespace Batch {
 
       // if the argument contains spaces, we surround it with simple quotes (Linux)
       // or double quotes (Windows)
-      if (commandArgs[i].find(' ') != string::npos) {
+      if (commandArgs[i].find(' ') != string::npos &&
+          !Utils::isOption(commandArgs[i])){
         commandStr += string("\"") + commandArgs[i] + "\"";
       } else {
         commandStr += commandArgs[i];