From ee3ee4a68c18097dcb3c712dce402ba8147dcdf1 Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Thu, 21 Jun 2007 15:21:25 +0000
Subject: [PATCH] recursively copy any content from the older installation's config directory after upgrading the bits during an upgrade

---
 opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java  |   50 ++++++++++++++++++++++++
 opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java |   64 ++++++++++++++-----------------
 2 files changed, 78 insertions(+), 36 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java b/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
index eb6d770..90899b2 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/upgrader/Upgrader.java
@@ -848,16 +848,7 @@
         setCurrentProgressStep(
                 UpgradeProgressStep.UPGRADING_COMPONENTS);
         upgradeComponents();
-
-        // The config directory may contain files that are needed
-        // by the new installation (e.g. SSL config files and tasks)
-        File oldConfigDir =
-                new File(getFilesBackupDirectory(),
-                         Installation.CONFIG_PATH_RELATIVE);
-        File newConfigDir =
-                getInstallation().getConfigurationDirectory();
-        copyNonexistentFiles(oldConfigDir, newConfigDir);
-
+        updateConfigDirectory();
         notifyListeners(formatter.getFormattedDone() +
                 formatter.getLineBreak());
         LOG.log(Level.INFO, "component upgrade finished");
@@ -1291,6 +1282,8 @@
                 getInstallation()).modify(configDiff);
 
       }
+    } catch (ApplicationException ae) {
+      throw ae;
     } catch (Exception e) {
       String msg = getMsg("error-applying-custom-config");
       LOG.log(Level.INFO, msg, e);
@@ -1306,6 +1299,8 @@
         new InProcessServerController(
                 getInstallation()).modify(schemaDiff);
       }
+    } catch (ApplicationException ae) {
+      throw ae;
     } catch (Exception e) {
       String msg = getMsg("error-applying-custom-schema");
       LOG.log(Level.INFO, msg, e);
@@ -1374,30 +1369,18 @@
     }
   }
 
-  /**
-   * Copies any files appearing in <code>source</code> and not appearing
-   * in <code>target</code> from <code>source</code> to
-   * <code>target</code>.
-   * @param source source directory
-   * @param target target directory
-   * @throws ApplicationException if there is a problem copying files
-   */
-  private void copyNonexistentFiles(File source, File target)
-          throws ApplicationException
+  private void updateConfigDirectory()
+          throws IOException,ApplicationException
   {
-    if (source != null && target != null) {
-      String[] oldFileNames = source.list();
-      if (oldFileNames != null) {
-        FileManager fm = new FileManager();
-        for (String oldFileName : oldFileNames) {
-          File f = new File(target, oldFileName);
-          if (!f.exists()) {
-            File oldFile = new File(source, oldFileName);
-            fm.copy(oldFile, target);
-          }
-        }
-      }
-    }
+    // The config directory may contain files that are needed
+    // by the new installation (e.g. SSL config files and tasks)
+    File oldConfigDir =
+            new File(getFilesBackupDirectory(),
+                     Installation.CONFIG_PATH_RELATIVE);
+    File newConfigDir =
+            getInstallation().getConfigurationDirectory();
+    FileManager fm = new FileManager();
+    fm.synchronize(oldConfigDir, newConfigDir);
   }
 
   private boolean calculateConfigCustomizations() throws ApplicationException {
@@ -1411,6 +1394,8 @@
           ldifDiff(getInstallation().getBaseConfigurationFile(),
                   getInstallation().getCurrentConfigurationFile(),
                   getCustomConfigDiffFile());
+        } catch (ApplicationException ae) {
+          throw ae;
         } catch (Exception e) {
           throw ApplicationException.createFileSystemException(
                   getMsg("error-determining-custom-config"), e);
@@ -1454,6 +1439,8 @@
         ldifDiff(getInstallation().getBaseSchemaFile(),
                 getInstallation().getSchemaConcatFile(),
                 getCustomSchemaDiffFile());
+      } catch (ApplicationException ae) {
+        throw ae;
       } catch (Exception e) {
         throw ApplicationException.createFileSystemException(
                 getMsg("error-determining-custom-schema"), e);
@@ -1475,6 +1462,8 @@
         //fm.copyRecursively(f, filesBackupDirectory,
         fm.move(f, filesBackupDirectory, filter);
       }
+    } catch (ApplicationException ae) {
+      throw ae;
     } catch (Exception e) {
       throw new ApplicationException(
               ApplicationException.Type.FILE_SYSTEM_ERROR,
@@ -1496,6 +1485,8 @@
                 null);
 
       }
+    } catch (ApplicationException ae) {
+      throw ae;
     } catch (Exception e) {
       throw new ApplicationException(
               ApplicationException.Type.TOOL_ERROR,
@@ -1541,7 +1532,8 @@
               writeInitialHistoricalRecord(fromVersion, toVersion);
 
       insureUpgradability();
-
+    } catch (ApplicationException ae) {
+      throw ae;
     } catch (Exception e) {
       throw new ApplicationException(
               ApplicationException.Type.FILE_SYSTEM_ERROR,
@@ -1572,6 +1564,8 @@
 
     try {
       newVersion = getStagedInstallation().getBuildInformation();
+    } catch (ApplicationException ae) {
+      throw ae;
     } catch (Exception e) {
       LOG.log(Level.INFO, "error getting build information for " +
               "staged installation", e);
@@ -1741,7 +1735,7 @@
     if (this.currentVersion == null) {
       try {
         currentVersion = getInstallation().getBuildInformation();
-      } catch (ApplicationException e) {
+      } catch (Exception e) {
         LOG.log(Level.INFO, "error trying to determine current version", e);
       }
     }
diff --git a/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java b/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
index 5a8aaba..f578716 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/util/FileManager.java
@@ -87,6 +87,43 @@
   }
 
   /**
+   * Recursively copies any files or directories appearing in
+   * <code>source</code> or a subdirectory of <code>source</code>
+   * to the corresponding directory under <code>target</code>.  Files
+   * in under <code>source</code> are not copied to <code>target</code>
+   * if a file by the same name already exists in <code>target</code>.
+   *
+   * @param source source directory
+   * @param target target directory
+   * @throws ApplicationException if there is a problem copying files
+   */
+  public void synchronize(File source, File target)
+          throws ApplicationException
+  {
+    if (source != null && target != null) {
+      String[] sourceFileNames = source.list();
+      if (sourceFileNames != null) {
+        for (String sourceFileName : sourceFileNames) {
+          File sourceFile = new File(source, sourceFileName);
+          copyRecursively(sourceFile, target, null, false);
+        }
+      }
+    }
+  }
+
+  /**
+   * Move a file.
+   * @param object File to move
+   * @param newParent File representing new parent directory
+   * @throws ApplicationException if something goes wrong
+   */
+  public void move(File object, File newParent)
+          throws ApplicationException
+  {
+    move(object, newParent, null);
+  }
+
+  /**
    * Move a file.
    * @param object File to move
    * @param newParent File representing new parent directory
@@ -106,6 +143,17 @@
   /**
    * Deletes a single file or directory.
    * @param object File to delete
+   * @throws ApplicationException if something goes wrong
+   */
+  public void delete(File object)
+          throws ApplicationException
+  {
+    delete(object, null);
+  }
+
+  /**
+   * Deletes a single file or directory.
+   * @param object File to delete
    * @param filter that will be asked whether or not the operation should be
    *        performed
    * @throws ApplicationException if something goes wrong
@@ -364,7 +412,7 @@
 
               if (destination.exists()) {
                 // TODO:  set the file's permissions.  This is made easier in
-                // Java 1.6 but until then use the Utils methods
+                // Java 1.6 but until then use the TestUtilities methods
                 if (Utils.isUnix()) {
                   String permissions =
                           Utils.getFileSystemPermissions(objectFile);

--
Gitblit v1.10.0