From fd10db6b0cbd40d3803e466e5e8c53bd85de9d64 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 02 Nov 2009 18:16:31 +0000
Subject: [PATCH] Fix for issue 4332 (Tools fail when instance path contains whitespace) The problem is in the code in charge of checking the install and instance paths and contents.  There are issues both in the scripts and in the code of org.opends.server.tools.configurator.CheckInstance.  Using quotes fixes the issue in the script and using an array of String instead of a single command-line to launch the "ls" process.

---
 opends/src/server/org/opends/server/tools/configurator/CheckInstance.java |   23 +++++++++++++++++------
 1 files changed, 17 insertions(+), 6 deletions(-)

diff --git a/opends/src/server/org/opends/server/tools/configurator/CheckInstance.java b/opends/src/server/org/opends/server/tools/configurator/CheckInstance.java
index b54ab67..7c9474c 100644
--- a/opends/src/server/org/opends/server/tools/configurator/CheckInstance.java
+++ b/opends/src/server/org/opends/server/tools/configurator/CheckInstance.java
@@ -213,16 +213,24 @@
      if (!isWin) {
     // Check user
     File conf = new File (confDir, Installation.CURRENT_CONFIG_FILE_NAME);
-    String cmd = null;
     Process proc = null;
     int exit = 0;
 
     InputStreamReader reader = null;
     int c;
     StringBuffer sb = new StringBuffer();
-    cmd = "ls -l " + conf.getAbsolutePath();
+    String[] cmdArgs = {"ls", "-l", conf.getAbsolutePath()};
+    StringBuilder cmd = new StringBuilder();
+    for (String arg : cmdArgs)
+    {
+      if (cmd.length() > 0)
+      {
+        cmd.append(" ");
+      }
+      cmd.append(arg);
+    }
     try {
-      proc = Runtime.getRuntime().exec(cmd);
+      proc = Runtime.getRuntime().exec(cmdArgs);
       proc.waitFor();
       reader = new InputStreamReader(proc.getInputStream());
       while (((c = reader.read()) != -1)) {
@@ -231,18 +239,21 @@
       exit = proc.exitValue();
       if (exit != 0) {
         LOG.log(Level.FINEST, cmd + " error= " + exit);
-        System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(conf.getAbsolutePath(),
+        System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(
+            confDir.getAbsolutePath(),
             installRootFromSystem + File.separator + "instance.loc"));
         System.exit(ReturnCode.APPLICATION_ERROR.getReturnCode());
       }
     } catch (InterruptedException ex) {
       LOG.log(Level.SEVERE, "InterruptedException" + ex.getMessage());
-      System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(conf.getAbsolutePath(),
+      System.err.println(
+          ERR_CONFIG_LDIF_NOT_FOUND.get(confDir.getAbsolutePath(),
           installRootFromSystem + File.separator + "instance.loc"));
       System.exit(ReturnCode.APPLICATION_ERROR.getReturnCode());
     } catch (IOException ex) {
       LOG.log(Level.SEVERE, "IOException" + ex.getMessage() );
-      System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(conf.getAbsolutePath(),
+      System.err.println(ERR_CONFIG_LDIF_NOT_FOUND.get(
+          confDir.getAbsolutePath(),
           installRootFromSystem + File.separator + "instance.loc"));
       System.exit(ReturnCode.APPLICATION_ERROR.getReturnCode());
     }

--
Gitblit v1.10.0