X-Git-Url: http://git.salome-platform.org/gitweb/?a=blobdiff_plain;f=src%2FCore%2FCommunicationProtocol.cxx;h=aaee92b1c16073fb9e3e8eaef4657cc9e3cf11a8;hb=cb7f594cea9015e986cafdeccf43b22742bf405e;hp=b7d298ae2730ee2487374cde2ca064bce6fabca4;hpb=19ceed0f6120390029bc645ad7768316b8d14de1;p=tools%2Flibbatch.git diff --git a/src/Core/CommunicationProtocol.cxx b/src/Core/CommunicationProtocol.cxx index b7d298a..aaee92b 100644 --- a/src/Core/CommunicationProtocol.cxx +++ b/src/Core/CommunicationProtocol.cxx @@ -1,23 +1,23 @@ -// Copyright (C) 2007-2013 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 +// Copyright (C) 2003-2007 OPEN CASCADE, EADS/CCR, LIP6, CEA/DEN, +// CEDRAT, EDF R&D, LEG, PRINCIPIA R&D, BUREAU VERITAS // -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License. +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public +// License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. // -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. +// This library is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +// Lesser General Public License for more details. // -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +// You should have received a copy of the GNU Lesser General Public +// License along with this library; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA // -// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com +// See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com // /* * CommunicationProtocol.cxx : @@ -28,7 +28,7 @@ #include -#include +#include #include "CommunicationProtocol.hxx" #ifdef HAS_RSH @@ -40,9 +40,13 @@ #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,12 +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, @@ -129,6 +158,16 @@ namespace Batch { return status; } + int CommunicationProtocol::removeDirectory(const std::string & path, + const std::string & host, + const std::string & user) const + { + string command = getExecCommand(getRemoveDirectorySubCommand(path), host, user); + LOG(command); + int status = system(command.c_str()); + return status; + } + int CommunicationProtocol::makeDirectory(const std::string & path, const std::string & host, const std::string & user) const @@ -154,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];