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

kenneth_suter
13.36.2007 ecd6711981fbd48a4a9bc376377ba6cc86c0c3fb
This commit addresses addresses problems with the file system locking files that arose from testing the upgrader on Windows.
3 files modified
69 ■■■■ changed files
opendj-sdk/opends/resource/upgrade.bat 24 ●●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java 18 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java 27 ●●●● patch | view | raw | blame | history
opendj-sdk/opends/resource/upgrade.bat
@@ -32,28 +32,25 @@
:checkJavaBin
if "%JAVA_BIN%" == "" goto noJavaBin
goto setClassPath
goto callExtractor
:noJavaBin
if "%JAVA_HOME%" == "" goto noJavaHome
if not exist "%JAVA_HOME%\bin\java.exe" goto noJavaHome
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
goto callExtractor
:noJavaHome
if not exist "%DIR_HOME%\bat\set-java-home.bat" goto noSetJavaHome
call "%DIR_HOME%\bat\set-java-home.bat"
set JAVA_BIN=%JAVA_HOME%\bin\java.exe
goto setClassPath
goto callExtractor
:noSetJavaHome
echo Error: JAVA_HOME environment variable is not set.
echo        Please set it to a valid Java 5 installation.
goto end
:setClassPath
FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\bat\setcp.bat" %%x
set PATH=%SystemRoot%
if "%*" == "" goto callLaunch
@@ -63,8 +60,19 @@
"%DIR_HOME%\lib\winlauncher.exe" launch "%DIR_HOME%" "%JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.upgrader.UpgradeLauncher
goto end
:callJava
"%JAVA_BIN%" %JAVA_ARGS% org.opends.quicksetup.upgrader.UpgradeLauncher %*
:callExtractor
if EXIST .\tmp\upgrade rd .\tmp\upgrade /s /q
set CLASSPATH=""
FOR %%x in ("%DIR_HOME%\lib\*.jar") DO call "%DIR_HOME%\bat\setcp.bat" %%x
"%JAVA_BIN%" org.opends.quicksetup.upgrader.BuildExtractor %*
if %ERRORLEVEL%==0 goto callUpgrader
goto end
:callUpgrader
set CLASSPATH=""
FOR %%x in ("%DIR_HOME%\tmp\upgrade\lib\*.jar") DO call "%DIR_HOME%\bat\setcp.bat" %%x
"%JAVA_BIN%" org.opends.quicksetup.upgrader.UpgradeLauncher %*
if EXIST .\tmp\upgrade rd .\tmp\upgrade /s /q
goto end
:end
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
@@ -233,7 +233,15 @@
   * {@inheritDoc}
   */
  protected String getInstallationPath() {
    return Utils.getInstallPathFromClasspath();
    // The upgrader runs from the bits extracted by BuildExtractor
    // in the staging directory.  So 'stagePath' below will point
    // to the staging directory [installroot]/tmp/upgrade.  However
    // we still want the Installation to point at the build being
    // upgraded so the install path reported in [installroot].
    String stagePath = Utils.getInstallPathFromClasspath();
    File f = new File(stagePath);
    return Utils.getPath(f.getParentFile().getParentFile());
  }
  /**
@@ -924,9 +932,11 @@
      stagingDir = getStageDirectory();
      FileManager fm = new FileManager(this);
      // doing this seems to work betterh than just plain
      // old delete
      fm.deleteRecursively(stagingDir);
      // Doing this seems to work better than just plain
      // old delete.  Note that on Windows there are file
      // locking issues to we mark files for deletion after
      // this JVM exits
      fm.deleteRecursively(stagingDir, null, /*onExit=*/true);
    } catch (IOException e) {
      // TODO i18n
opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
@@ -77,7 +77,7 @@
          throws ApplicationException
  {
    if (filter == null || filter.accept(object)) {
      new DeleteOperation(object).apply();
      new DeleteOperation(object, false).apply();
    }
  }
@@ -88,7 +88,7 @@
   * @throws org.opends.quicksetup.ApplicationException if something goes wrong.
   */
  public void deleteRecursively(File file) throws ApplicationException {
    deleteRecursively(file, null);
    deleteRecursively(file, null, false);
  }
  /**
@@ -97,11 +97,13 @@
   * @param file   the path to be deleted.
   * @param filter the filter of the files to know if the file can be deleted
   *               directly or not.
   * @param onExit when true just marks the files for deletion after the
   *        JVM exits rather than deleting the files immediately.
   * @throws ApplicationException if something goes wrong.
   */
  public void deleteRecursively(File file, FileFilter filter)
  public void deleteRecursively(File file, FileFilter filter, boolean onExit)
          throws ApplicationException {
    operateRecursively(new DeleteOperation(file), filter);
    operateRecursively(new DeleteOperation(file, onExit), filter);
  }
  /**
@@ -351,19 +353,25 @@
   */
  private class DeleteOperation extends FileOperation {
    private boolean afterExit;
    /**
     * Creates a delete operation.
     * @param objectFile to delete
     * @param afterExit boolean indicates that the actual delete
     * is to take place after this program exists.  This is useful
     * for cleaning up files that are currently in use.
     */
    public DeleteOperation(File objectFile) {
    public DeleteOperation(File objectFile, boolean afterExit) {
      super(objectFile);
      this.afterExit = afterExit;
    }
    /**
     * {@inheritDoc}
     */
    public FileOperation copyForChild(File child) {
      return new DeleteOperation(child);
      return new DeleteOperation(child, afterExit);
    }
    /**
@@ -390,7 +398,12 @@
       */
      int nTries = 5;
      for (int i = 0; i < nTries && !delete; i++) {
        delete = file.delete();
        if (afterExit) {
          file.deleteOnExit();
          delete = true;
        } else {
          delete = file.delete();
        }
        if (!delete) {
          try {
            Thread.sleep(1000);