mirror of https://github.com/OpenIdentityPlatform/OpenDJ.git

jvergara
26.22.2007 bcdab6d3104e368c131bf63d91866fec130c4481
Fix for issue 1432 (Uninstall fails on windows due to lock on activation.jar).

There are two things fixed here: with AspectJ we have more jar dependencies when running the uninstaller so just tell the user at the end to delete the files under the lib directory (instead of just deleting a couple of jars).

The other problem that I have encountered is that when we try to delete the server.lock file (even if the server is not running) we cannot do it because there are some references to the file. This is caused because when we call the method LockFileManager.acquireExclusiveLock when the acquisition of the lock fails we do not close the FileChannel nor the RandomAccessFile that we are opening to try to get the lock. The modifications in LockFileManager just close the RandomAccessFile and the FileChannel that have been opened when we could not get the lock (is just a clean up).
4 files modified
240 ■■■■ changed files
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CurrentInstallStatus.java 1 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/UninstallCli.java 109 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java 18 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/server/org/opends/server/core/LockFileManager.java 112 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/CurrentInstallStatus.java
@@ -253,7 +253,6 @@
    }
    catch (Throwable t)
    {
      t.printStackTrace();
      // Assume that if we cannot acquire the lock file the server is
      // running.
      isServerRunning = true;
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/UninstallCli.java
@@ -27,9 +27,9 @@
package org.opends.quicksetup.uninstaller;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.FileReader;
import java.util.ArrayList;
import java.util.Set;
@@ -288,34 +288,7 @@
    return response;
  }
  /**
   * Interactively prompts (on standard output) the user to provide a string
   * value.  Any non-empty string will be allowed (the empty string will
   * indicate that the default should be used).
   *
   * @param  prompt        The prompt to present to the user.
   * @param  defaultValue  The default value returned if the user clicks enter.
   *
   * @return  The string value read from the user.
   */
  private String promptForString(String prompt, String defaultValue)
  {
    System.out.println();
    String response = null;
    String msg = getMsg("cli-uninstall-string-prompt",
        new String[] {prompt, defaultValue});
    System.out.print(msg);
    System.out.flush();
    response = readLine();
    if (response.equals(""))
    {
      response = defaultValue;
    }
    return response;
  }
  /**
   * Reads a line of text from standard input.
@@ -577,7 +550,7 @@
  {
    boolean cancelled = false;
    if (installStatus.isServerRunning())
    if (CurrentInstallStatus.isServerRunning())
    {
        if (!silentUninstall)
        {
@@ -588,7 +561,7 @@
        if (!cancelled)
        {
            /* During all the confirmations, the server might be stopped. */
            userData.setStopServer(installStatus.isServerRunning());
            userData.setStopServer(CurrentInstallStatus.isServerRunning());
        }
    }
    else
@@ -636,9 +609,6 @@
  private void validateArguments(UserUninstallData userData,
      String[] args) throws UserUninstallDataException
  {
    String directoryManagerPwd = null;
    String directoryManagerPwdFile = null;
    ArrayList<String> errors = new ArrayList<String>();
    for (int i=0; i<args.length; i++)
@@ -667,77 +637,6 @@
  }
  /**
   * Interactively prompts (on standard output) the user to provide a string
   * value.
   *
   * @param  prompt  The prompt to present to the user.
   *
   * @return  The string value read from the user.
   */
  private String promptForPassword(String prompt)
  {
    char[] password = null;
    while ((password == null) || (password.length == 0))
    {
      System.out.println();
      System.out.print(prompt);
      System.out.flush();
      password = org.opends.server.util.PasswordReader.readPassword();
    }
    return new String(password);
  }
  /**
   * Returns the password stored in a file.  Returns <CODE>null</CODE> if no
   * password is found.
   * @param path the path of the file containing the password.
   * @return the password stored in a file.  Returns <CODE>null</CODE> if no
   * password is found.
   */
  private String readPwdFromFile(String path)
  {
    String pwd = null;
    BufferedReader reader = null;
    try
    {
      reader = new BufferedReader(new FileReader(path));
      pwd = reader.readLine();
    }
    catch (Exception e)
    {
    }
    finally
    {
      try
      {
        if (reader != null)
        {
          reader.close();
        }
      } catch (Exception e) {}
    }
    return pwd;
  }
  /**
   * Method used to know if we can connect as administrator in a server with a
   * given password and dn.
   * @param ldapUrl the ldap URL of the server.
   * @param dn the dn to be used.
   * @param pwd the password to be used.
   * @return <CODE>true</CODE> if we can connect and read the configuration and
   * <CODE>false</CODE> otherwise.
   */
  private boolean canConnectAsAdministrativeUser(String ldapUrl, String dn,
      String pwd)
  {
    return Utils.canConnectAsAdministrativeUser(ldapUrl, dn, pwd);
  }
  /**
   *  Ask for confirmation to stop server.
   *  @return <CODE>true</CODE> if the user wants to continue and stop the
   *  server.  <CODE>false</CODE> otherwise.
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/uninstaller/Uninstaller.java
@@ -527,6 +527,10 @@
      if (isWindowsServiceEnabled())
      {
        status = UninstallProgressStep.DISABLING_WINDOWS_SERVICE;
        if (displaySeparator)
        {
          notifyListeners(getTaskSeparator());
        }
        disableWindowsService();
        displaySeparator = true;
      }
@@ -943,14 +947,7 @@
    return Utils.getPath(getLibrariesPath(), "OpenDS.jar");
  }
  /**
   * Returns the path to the aspectj jar file.
   * @return the path to the aspectj jar file.
   */
  private String getAspectJJarPath()
  {
    return Utils.getPath(getLibrariesPath(), "aspectjrt.jar");
  }
  /**
@@ -1183,7 +1180,7 @@
            String line = reader.readLine();
            while (line != null)
            {
              StringBuffer buf = new StringBuffer();
              StringBuilder buf = new StringBuilder();
              if (!isFirstLine)
              {
                buf.append(formatter.getLineBreak());
@@ -1257,7 +1254,7 @@
     boolean accept =
          !installationPath.equals(file)
              && !librariesFile.equals(file)
              && !equalsOrDescendant(file, librariesFile)
              && !quicksetupFile.equals(file)
              && !openDSFile.equals(file);
@@ -1434,3 +1431,4 @@
    }
  }
}
opendj-sdk/opends/src/server/org/opends/server/core/LockFileManager.java
@@ -138,10 +138,11 @@
      // Open the file for reading and get the corresponding file channel.
      FileChannel channel;
      FileChannel channel = null;
      RandomAccessFile raf = null;
      try
      {
        RandomAccessFile raf = new RandomAccessFile(lockFile, "r");
        raf = new RandomAccessFile(lockFile, "r");
        channel = raf.getChannel();
      }
      catch (Exception e)
@@ -154,6 +155,17 @@
        int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_OPEN;
        failureReason.append(getMessage(msgID, lockFile,
                                        stackTraceToSingleLineString(e)));
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        return false;
      }
@@ -174,6 +186,26 @@
        int msgID = MSGID_FILELOCKER_LOCK_SHARED_FAILED_LOCK;
        failureReason.append(getMessage(msgID,
                                        stackTraceToSingleLineString(e)));
        if (channel != null)
        {
          try
          {
            channel.close();
          }
          catch (Throwable t)
          {
          }
        }
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        return false;
      }
@@ -184,6 +216,26 @@
      {
        int msgID = MSGID_FILELOCKER_LOCK_SHARED_NOT_GRANTED;
        failureReason.append(getMessage(msgID, lockFile));
        if (channel != null)
        {
          try
          {
            channel.close();
          }
          catch (Throwable t)
          {
          }
        }
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        return false;
      }
      else
@@ -263,10 +315,11 @@
      // Open the file read+write and get the corresponding file channel.
      FileChannel channel;
      FileChannel channel = null;
      RandomAccessFile raf = null;
      try
      {
        RandomAccessFile raf = new RandomAccessFile(lockFile, "rw");
        raf = new RandomAccessFile(lockFile, "rw");
        channel = raf.getChannel();
      }
      catch (Exception e)
@@ -279,6 +332,16 @@
        int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_OPEN;
        failureReason.append(getMessage(msgID, lockFile,
                                        stackTraceToSingleLineString(e)));
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        return false;
      }
@@ -299,6 +362,27 @@
        int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_FAILED_LOCK;
        failureReason.append(getMessage(msgID, lockFile,
                                        stackTraceToSingleLineString(e)));
        if (channel != null)
        {
          try
          {
            channel.close();
          }
          catch (Throwable t)
          {
          }
        }
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        return false;
      }
@@ -309,6 +393,26 @@
      {
        int msgID = MSGID_FILELOCKER_LOCK_EXCLUSIVE_NOT_GRANTED;
        failureReason.append(getMessage(msgID, lockFile));
        if (channel != null)
        {
          try
          {
            channel.close();
          }
          catch (Throwable t)
          {
          }
        }
        if (raf != null)
        {
          try
          {
            raf.close();
          }
          catch (Throwable t)
          {
          }
        }
        return false;
      }
      else