From 49aa9ac936e07937b7e08b17759f904e2f10d3fb Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Thu, 20 Sep 2007 19:31:21 +0000
Subject: [PATCH] Fix for issue 2227 in which unpredictable behavior results from an upgrade or reversion process replacing the upgrade script while the upgrade process is running on Windows.  This code will compare the running version of the script with the new version to see whether or not the script actually needs replacing.  If so the script is copied with an extension NEW.  When the script starts it checks for the existence of upgrade.bat.NEW and if exists prints a message informing the user that they must replace the old version of the script with the new version before continuing.

---
 opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java |   51 +++++++++++++++++++++++++++++++++++++--------------
 1 files changed, 37 insertions(+), 14 deletions(-)

diff --git a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
index d9d8a5a..0c39f3d 100644
--- a/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
+++ b/opendj-sdk/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
@@ -148,11 +148,6 @@
   private ApplicationException runWarning = null;
 
   /**
-   * Helps with CLI specific tasks.
-   */
-  private UpgraderCliHelper cliHelper = null;
-
-  /**
    * Directory where backup is kept in case the upgrade needs reversion.
    */
   private File backupDirectory = null;
@@ -178,8 +173,16 @@
    */
   private Installation stagedInstallation = null;
 
+  // TODO: remove dead code
   private RemoteBuildManager remoteBuildManager = null;
 
+
+  /**
+   * Represents staged files for upgrade.
+   */
+  private Stage stage = null;
+
+
   /** Set to true if the user decides to close the window while running. */
   private boolean abort = false;
 
@@ -1026,6 +1029,17 @@
                     Utils.getPath(getInstallation().getHistoryLogFile())))
                 .append(formatter.getLineBreak())
                 .toMessage());
+
+        try {
+          Stage stage = getStage();
+          List<Message> stageMessages = stage.getMessages();
+          for (Message m : stageMessages) {
+            notifyListeners(m);
+          }
+        } catch (IOException e) {
+          LOG.log(Level.INFO, "failed to access stage", e);
+        }
+
       } catch (ApplicationException e) {
         notifyListeners(getFormattedErrorWithLineBreak());
         LOG.log(Level.INFO, "Error cleaning up after upgrade.", e);
@@ -1164,18 +1178,19 @@
 
   }
 
+  private Stage getStage() throws IOException, ApplicationException {
+    if (this.stage == null) {
+      this.stage = new Stage(getStageDirectory());
+    }
+    return this.stage;
+  }
+
   private void upgradeComponents() throws ApplicationException {
     try {
-      File stageDir = getStageDirectory();
+      Stage stage = getStage();
       Installation installation = getInstallation();
       File root = installation.getRootDirectory();
-      FileManager fm = new FileManager();
-      for (String fileName : stageDir.list()) {
-        File f = new File(stageDir, fileName);
-        fm.copyRecursively(f, root,
-                new UpgradeFileFilter(stageDir),
-                /*overwrite=*/true);
-      }
+      stage.move(root);
 
       // The bits should now be of the new version.  Have
       // the installation update the build information so
@@ -1223,7 +1238,15 @@
       FileFilter filter = new UpgradeFileFilter(root);
       for (String fileName : root.list()) {
         File f = new File(root, fileName);
-        //fm.copyRecursively(f, filesBackupDirectory,
+
+        // Replacing a Windows bat file while it is running with a different
+        // version leads to unpredictable behavior so we make a special case
+        // here and during the upgrade components step.
+        if (Utils.isWindows() &&
+                fileName.equals(Installation.WINDOWS_UPGRADE_FILE_NAME)) {
+          continue;
+        }
+
         fm.move(f, filesBackupDirectory, filter);
       }
     } catch (ApplicationException ae) {

--
Gitblit v1.10.0