From: Ovidiu Mircescu Date: Wed, 25 Oct 2017 09:40:37 +0000 (+0200) Subject: Add remove working directory feature. X-Git-Tag: V2_4_0~5 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=bfc4327ba73cb90b9a00dd2ee343943e08dabae0;p=tools%2Flibbatch.git Add remove working directory feature. --- diff --git a/src/Core/BatchManager.cxx b/src/Core/BatchManager.cxx index 8194c16..4645ffb 100644 --- a/src/Core/BatchManager.cxx +++ b/src/Core/BatchManager.cxx @@ -315,6 +315,21 @@ namespace Batch { return ret; } + void BatchManager::clearWorkingDir( const Job & job) + { + Parametre params = job.getParametre(); + + string wd = params[WORKDIR]; + if(!wd.empty() && wd != "/") + { + int status = _protocol.removeDirectory(wd, _hostname, _username); + if (status) + LOG("removeDirectory command failed. Status is: " << status); + } + else + LOG("removeDirectory command failed. Invalid working directory: " << wd); + } + MpiImpl *BatchManager::FactoryMpiImpl(string mpiImpl) { if(mpiImpl == "lam") diff --git a/src/Core/BatchManager.hxx b/src/Core/BatchManager.hxx index c223363..7d78f9c 100644 --- a/src/Core/BatchManager.hxx +++ b/src/Core/BatchManager.hxx @@ -79,6 +79,7 @@ namespace Batch { bool importDumpStateFile( const Job & job, const std::string directory ); // copier le fichier work_file à partir du working_directory vers directory virtual bool importWorkFile( const Job & job, const std::string& work_file, const std::string& directory ); + virtual void clearWorkingDir( const Job & job ); // Get the underlying communication protocol const CommunicationProtocol & getProtocol() const; diff --git a/src/Core/CommunicationProtocol.cxx b/src/Core/CommunicationProtocol.cxx index 380f780..57a1d52 100644 --- a/src/Core/CommunicationProtocol.cxx +++ b/src/Core/CommunicationProtocol.cxx @@ -114,6 +114,11 @@ namespace Batch { return string("rm ") + path; } + string CommunicationProtocol::getRemoveDirectorySubCommand(const string & path) const + { + return string("rm -fR ") + path; + } + string CommunicationProtocol::getMakeDirectorySubCommand(const string & path) const { return string("mkdir -p ") + path; @@ -129,6 +134,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 diff --git a/src/Core/CommunicationProtocol.hxx b/src/Core/CommunicationProtocol.hxx index 5f6356b..3dc6133 100644 --- a/src/Core/CommunicationProtocol.hxx +++ b/src/Core/CommunicationProtocol.hxx @@ -64,6 +64,10 @@ namespace Batch { const std::string & host, const std::string & user) const; + virtual int removeDirectory(const std::string & path, + const std::string & host, + const std::string & user) const; + virtual int makeDirectory(const std::string & path, const std::string & host, const std::string & user) const; @@ -83,6 +87,8 @@ namespace Batch { virtual std::string getRemoveSubCommand(const std::string & path) const; + virtual std::string getRemoveDirectorySubCommand(const std::string & path) const; + virtual std::string getMakeDirectorySubCommand(const std::string & path) const; std::string commandStringFromArgs(const std::vector & args) const;