From 4978cbcfce206fb43659395556b59c33127505bd Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Mon, 07 Apr 2008 11:56:09 +0000
Subject: [PATCH] Fix for issue 3121 (Bad management of upgrade -r on a already reverted installation)

---
 opends/src/quicksetup/org/opends/quicksetup/upgrader/Reverter.java |   21 ++++++++++++++++++++-
 1 files changed, 20 insertions(+), 1 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/upgrader/Reverter.java b/opends/src/quicksetup/org/opends/quicksetup/upgrader/Reverter.java
index 89da102..52b622d 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/upgrader/Reverter.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/upgrader/Reverter.java
@@ -260,6 +260,7 @@
             }
           };
           String[] childNames = historyDir.list(filter);
+          boolean found = false;
           if (childNames != null && childNames.length > 0) {
 
             // The directories beneath 'history' are named according
@@ -272,11 +273,16 @@
               File b = new File(historyDir, childName);
               File d = new File(b, HISTORY_BACKUP_FILES_DIR_NAME);
               if (isReversionFilesDirectory(d)) {
+                found = true;
                 ud.setReversionArchiveDirectory(d);
                 break;
               }
             }
-
+            if (!found)
+            {
+              throw new UserDataException(null,
+                  INFO_REVERT_ERROR_INVALID_HISTORY_DIR.get());
+            }
           } else {
             throw new UserDataException(null,
                     INFO_REVERT_ERROR_EMPTY_HISTORY_DIR.get());
@@ -499,6 +505,12 @@
         if (toBi != null) {
           toBuildString = toBi.toString();
         } else {
+          if (getReversionFilesDirectory() == null)
+          {
+            throw new ApplicationException(
+                ReturnCode.APPLICATION_ERROR,
+                INFO_REVERT_ERROR_INVALID_HISTORY_DIR.get(), null);
+          }
           toBuildString = INFO_UPGRADE_BUILD_ID_UNKNOWN.get().toString();
         }
         if (cancel.equals(ui.confirm(
@@ -896,8 +908,14 @@
     FileManager fm = new FileManager();
     try {
       fm.deleteRecursively(getReversionFilesDirectory());
+      File parent = getReversionFilesDirectory().getParentFile();
+      if (Utils.directoryExistsAndIsEmpty(parent.getAbsolutePath()))
+      {
+        fm.deleteRecursively(parent);
+      }
     } catch (Exception e) {
       // ignore; this is best effort
+      LOG.log(Level.WARNING, "Error: "+e, e);
     }
   }
 
@@ -910,6 +928,7 @@
       fm.deleteRecursively(getTempBackupDirectory());
     } catch (Exception e) {
       // ignore; this is best effort
+      LOG.log(Level.WARNING, "Error: "+e, e);
     }
   }
 

--
Gitblit v1.10.0