From b2ac7520de046c34bcea83a2b6afe0ddbd4c4453 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Tue, 08 Jan 2008 16:32:20 +0000
Subject: [PATCH] Fix for issue 2784 (Revert doesn't set back the old upgrade.bat)

---
 opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java |   34 ++++++++++++++++++++++++++++++++--
 1 files changed, 32 insertions(+), 2 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java b/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
index 9247880..9b28a53 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Portions Copyright 2008 Sun Microsystems, Inc.
+ *      Portions Copyright 2007-2008 Sun Microsystems, Inc.
  */
 
 package org.opends.quicksetup.upgrader;
@@ -1114,6 +1114,7 @@
         String note = null;
         if (runError == null && !abort) {
           status = HistoricalRecord.Status.SUCCESS;
+          backupWindowsUpgradeFile();
         } else {
           if (abort) {
             status = HistoricalRecord.Status.CANCEL;
@@ -1409,7 +1410,8 @@
 
         // 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.
+        // here and during the upgrade components step.  This file will only
+        // be backed up at the end of the process if everything went fine.
         if (Utils.isWindows() &&
                 fileName.equals(Installation.WINDOWS_UPGRADE_FILE_NAME)) {
           continue;
@@ -1427,6 +1429,34 @@
     }
   }
 
+  /**
+   * This method is called at the end of the upgrade process if everything went
+   * fine since the reverter requires to have the upgrade file to properly
+   * complete (see issue 2784).
+   * @throws ApplicationException if there was an error backing up the upgrade
+   * file.
+   */
+  private void backupWindowsUpgradeFile() throws ApplicationException {
+    try
+    {
+      if (Utils.isWindows())
+      {
+        File filesBackupDirectory = getFilesBackupDirectory();
+        FileManager fm = new FileManager();
+        File root = getInstallation().getRootDirectory();
+        File f = new File(root, Installation.WINDOWS_UPGRADE_FILE_NAME);
+        fm.copy(f, filesBackupDirectory);
+      }
+    } catch (ApplicationException ae) {
+      throw ae;
+    } catch (Exception e) {
+      throw new ApplicationException(
+          ReturnCode.FILE_SYSTEM_ACCESS_ERROR,
+              INFO_ERROR_BACKUP_FILESYSTEM.get(),
+              e);
+    }
+  }
+
   private void backupDatabases() throws ApplicationException {
     try {
       ExternalTools et = new ExternalTools(getInstallation());

--
Gitblit v1.10.0