From c29c87db0976cb89e7c8da1e83497f9456c6c66b Mon Sep 17 00:00:00 2001 From: Ovidiu Mircescu Date: Fri, 29 Dec 2017 16:16:25 +0100 Subject: [PATCH] Get results from sub directories. --- src/Core/BatchManager.cxx | 4 ++++ src/Core/Utils.cxx | 14 ++++++++++++++ src/Core/Utils.hxx | 8 ++++++++ 3 files changed, 26 insertions(+) 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 -- 2.39.2