Salome HOME
Get results from sub directories.
authorOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Fri, 29 Dec 2017 15:16:25 +0000 (16:16 +0100)
committerOvidiu Mircescu <ovidiu.mircescu@edf.fr>
Fri, 29 Dec 2017 15:16:25 +0000 (16:16 +0100)
src/Core/BatchManager.cxx
src/Core/Utils.cxx
src/Core/Utils.hxx

index c50266fe91d184415ec81cce0d54b268fc1e8331..047b1ed20e3cdc120d00e1ed62d1d0a05ff46b63 100644 (file)
@@ -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)
index 15afb5feffb5eaee3ddc8091b0e28a2dcfaf03b2..cd3deb0455a59950ed2a0b0de7f51a2eee15206e 100644 (file)
@@ -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())
index 561d014f78d995bc0e1101c084d476ed6754fb52..ed208125ea58825c20b722f3db8814af48882398 100644 (file)
@@ -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 "<tmpdir>/libbatch-<prefix>-XXXXXX" where <tmpdir> is the