From 80d87dff17669f3d02016bf41d99ca41762abc1c Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 07 Oct 2009 12:43:38 +0000
Subject: [PATCH] Fix for issue 4271 (control-panel: in remote mode, "Installation Path" is incorrect) Since using File when you have different OS in the control panel and in the managed server can be really problematic, use String instead in the ServerDescriptor object.

---
 opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ServerDescriptor.java |   87 ++++++++++++++++++++++++++++++++++++++++---
 1 files changed, 81 insertions(+), 6 deletions(-)

diff --git a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ServerDescriptor.java b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ServerDescriptor.java
index 072aef1..47901a7 100644
--- a/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ServerDescriptor.java
+++ b/opendj-sdk/opends/src/guitools/org/opends/guitools/controlpanel/datamodel/ServerDescriptor.java
@@ -28,6 +28,7 @@
 package org.opends.guitools.controlpanel.datamodel;
 
 import java.io.File;
+import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
@@ -45,6 +46,7 @@
 import org.opends.server.types.DN;
 import org.opends.server.types.ObjectClass;
 import org.opends.server.types.OpenDsException;
+import org.opends.server.types.OperatingSystem;
 import org.opends.server.types.Schema;
 
 /**
@@ -60,8 +62,8 @@
     new HashSet<ConnectionHandlerDescriptor>();
   private ConnectionHandlerDescriptor adminConnector;
   private Set<DN> administrativeUsers = new HashSet<DN>();
-  private File installPath;
-  private File instancePath;
+  private String installPath;
+  private String instancePath;
   private String openDSVersion;
   private String javaVersion;
   private ArrayList<OpenDsException> exceptions =
@@ -185,7 +187,7 @@
    * @return the instance path where the server databases and configuration is
    * located
    */
-  public File getInstancePath()
+  public String getInstancePath()
   {
     return instancePath;
   }
@@ -196,7 +198,7 @@
    * @param instancePath the instance path where the server databases and
    * configuration is located.
    */
-  public void setInstancePath(File instancePath)
+  public void setInstancePath(String instancePath)
   {
     this.instancePath = instancePath;
   }
@@ -205,7 +207,7 @@
    * Return the install path where the server is installed.
    * @return the install path where the server is installed.
    */
-  public File getInstallPath()
+  public String getInstallPath()
   {
     return installPath;
   }
@@ -214,12 +216,49 @@
    * Sets the install path where the server is installed.
    * @param installPath the install path where the server is installed.
    */
-  public void setInstallPath(File installPath)
+  public void setInstallPath(String installPath)
   {
     this.installPath = installPath;
   }
 
   /**
+   * Returns whether the install and the instance are on the same server
+   * or not.
+   * @return whether the install and the instance are on the same server
+   * or not.
+   */
+  public boolean sameInstallAndInstance()
+  {
+    boolean sameInstallAndInstance;
+    String instance = getInstancePath();
+    String install = getInstallPath();
+    try
+    {
+      if (instance != null)
+      {
+        sameInstallAndInstance = instance.equals(install);
+        if (!sameInstallAndInstance &&
+            (isLocal() || (isWindows() == Utilities.isWindows())))
+        {
+          File f1 = new File(instance);
+          File f2 = new File(install);
+          sameInstallAndInstance =
+            f1.getCanonicalFile().equals(f2.getCanonicalFile());
+        }
+      }
+      else
+      {
+        sameInstallAndInstance = install == null;
+      }
+    }
+    catch (IOException ioe)
+    {
+      sameInstallAndInstance = false;
+    }
+    return sameInstallAndInstance;
+  }
+
+  /**
    * Return the java version used to run the server.
    * @return the java version used to run the server.
    */
@@ -615,6 +654,42 @@
   }
 
   /**
+   * Returns whether the server is running under a windows system or not.
+   * @return whether the server is running under a windows system or not.
+   */
+  public boolean isWindows()
+  {
+    boolean isWindows;
+    if (isLocal())
+    {
+      isWindows = Utilities.isWindows();
+    }
+    else
+    {
+      CustomSearchResult sr = getSystemInformationMonitor();
+      if (sr == null)
+      {
+        isWindows = false;
+      }
+      else
+      {
+        String os =
+          (String)Utilities.getFirstMonitoringValue(sr, "operatingSystem");
+        if (os == null)
+        {
+          isWindows = false;
+        }
+        else
+        {
+          OperatingSystem oSystem = OperatingSystem.forName(os);
+          isWindows = OperatingSystem.WINDOWS == oSystem;
+        }
+      }
+    }
+    return isWindows;
+  }
+
+  /**
    * Method used to compare schemas.
    * Returns <CODE>true</CODE> if the two schemas are equal and
    * <CODE>false</CODE> otherwise.

--
Gitblit v1.10.0