From d2528bf8de1d6bdbf94d44344857cb1837982765 Mon Sep 17 00:00:00 2001
From: cramakri <cramakri>
Date: Tue, 8 Jun 2010 11:32:41 +0000
Subject: [PATCH] LMS-1564 Fixed bug in transmitting folders with the put
 command.

SVN: 16334
---
 .../etlserver/api/v1/PutDataSetExecutor.java  | 17 +++++++++++++----
 .../dss/client/api/cli/CommandPut.java        | 19 ++++++++++++++-----
 2 files changed, 27 insertions(+), 9 deletions(-)

diff --git a/datastore_server/source/java/ch/systemsx/cisd/etlserver/api/v1/PutDataSetExecutor.java b/datastore_server/source/java/ch/systemsx/cisd/etlserver/api/v1/PutDataSetExecutor.java
index 7a50c691afb..f62dc37eb4d 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/etlserver/api/v1/PutDataSetExecutor.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/etlserver/api/v1/PutDataSetExecutor.java
@@ -147,10 +147,19 @@ class PutDataSetExecutor
                 new ConcatenatedFileOutputStreamWriter(inputStream);
         for (FileInfoDssDTO fileInfo : newDataSet.getFileInfos())
         {
-            OutputStream output = getOutputStream(fileInfo);
-            imagesWriter.writeNextBlock(output);
-            output.flush();
-            output.close();
+            if (fileInfo.isDirectory())
+            {
+                // Just make the directory
+                File file = new File(dataSetDir, fileInfo.getPathInDataSet());
+                file.mkdir();
+            } else
+            {
+                // Download the file -- the directory should have already been made
+                OutputStream output = getOutputStream(fileInfo);
+                imagesWriter.writeNextBlock(output);
+                output.flush();
+                output.close();
+            }
         }
     }
 
diff --git a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/cli/CommandPut.java b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/cli/CommandPut.java
index 36d3b022da6..e6334ca97cd 100644
--- a/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/cli/CommandPut.java
+++ b/datastore_server/source/java/ch/systemsx/cisd/openbis/dss/client/api/cli/CommandPut.java
@@ -66,7 +66,7 @@ class CommandPut extends AbstractCommand
 
         public String getFilePath()
         {
-            return getArguments().get(1);
+            return getArguments().get(2);
         }
 
         public File getFile()
@@ -85,7 +85,7 @@ class CommandPut extends AbstractCommand
 
             try
             {
-                DataSetOwnerType.valueOf(getArguments().get(1).toString().toUpperCase());
+                getOwnerType();
             } catch (IllegalArgumentException e)
             {
                 return false;
@@ -191,7 +191,16 @@ class CommandPut extends AbstractCommand
 
             for (FileInfoDssDTO fileInfo : fileInfos)
             {
-                files.add(new File(parent, fileInfo.getPathInDataSet()));
+                File file = new File(parent, fileInfo.getPathInDataSet());
+                if (false == file.exists())
+                {
+                    throw new IllegalArgumentException("File does not exist " + file);
+                }
+                // Skip directories
+                if (false == file.isDirectory())
+                {
+                    files.add(file);
+                }
             }
 
             return files;
@@ -248,8 +257,8 @@ class CommandPut extends AbstractCommand
         parser.printUsage(out);
         out.println("  Examples : ");
         out.println("     " + getCommandCallString() + parser.printExample(ExampleMode.ALL)
-                + " HCS_IMAGE EXPERIMENT <experiment identifier> <path>");
+                + " EXPERIMENT <experiment identifier> <path>");
         out.println("     " + getCommandCallString() + parser.printExample(ExampleMode.ALL)
-                + " HCS_IMAGE SAMPLE <sample identifier> <path>");
+                + " SAMPLE <sample identifier> <path>");
     }
 }
-- 
GitLab