From: Ovidiu Mircescu Date: Fri, 29 Dec 2017 15:16:25 +0000 (+0100) Subject: Get results from sub directories. X-Git-Tag: V2_4_0~3 X-Git-Url: http://git.salome-platform.org/gitweb/?a=commitdiff_plain;h=c29c87db0976cb89e7c8da1e83497f9456c6c66b;p=tools%2Flibbatch.git Get results from sub directories. --- diff --git a/src/Core/BatchManager.cxx b/src/Core/BatchManager.cxx index c50266f..047b1ed 100644 --- a/src/Core/BatchManager.cxx +++ b/src/Core/BatchManager.cxx @@ -263,6 +263,10 @@ namespace Batch { if (!Utils::isAbsolutePath(localPath)) { localPath = directory + "/" + localPath; } + status = CommunicationProtocol::getInstance(SH).makeDirectory( + Utils::dirname(localPath), "", ""); + if (status) + LOG("Directory creation failed. Status is: " << status); status = _protocol.copyFile(remotePath, _hostname, _username, localPath, "", ""); if (status) diff --git a/src/Core/Utils.cxx b/src/Core/Utils.cxx index 15afb5f..cd3deb0 100644 --- a/src/Core/Utils.cxx +++ b/src/Core/Utils.cxx @@ -83,6 +83,20 @@ bool Utils::isAbsolutePath(const string & path) return path[0] == '/'; } +std::string Utils::dirname(const std::string & path) +{ +#ifdef WIN32 + const char separator = '\\'; +#else + const char separator = '/'; +#endif + std::size_t found = path.rfind(separator); + if(found != std::string::npos) + return path.substr(0, found+1); + else + return std::string("."); +} + string Utils::createAndOpenTemporaryFile(const string & prefix, ofstream & outputStream) { if (outputStream.is_open()) diff --git a/src/Core/Utils.hxx b/src/Core/Utils.hxx index 561d014..ed20812 100644 --- a/src/Core/Utils.hxx +++ b/src/Core/Utils.hxx @@ -48,6 +48,14 @@ public: */ static bool isAbsolutePath(const std::string & path); + /** + * Returns the directory name of a path. + * "/a/b/file.txt" -> "/a/b" + * "a/file.txt" -> "a" + * "file.txt" -> "." + */ + static std::string dirname(const std::string & path); + /** * Create a temporary file and open an output stream to write into this file. * The file is created with the pattern "/libbatch--XXXXXX" where is the