From 8636196599847e5fa861942f382353b90eae517e Mon Sep 17 00:00:00 2001
From: kenneth_suter <kenneth_suter@localhost>
Date: Tue, 26 Jun 2007 21:03:20 +0000
Subject: [PATCH] Addresses a problem encountered in the upgrader on Windows in which configuration changes made to the server using an internal connection where not persisted in the config.ldif file.  The problem appears to have been an unclosed stream that was preventing the renaming of config.ldif.tmp to config.ldif.

---
 opends/src/server/org/opends/server/extensions/ConfigFileHandler.java |   23 ++++++++++++++++++-----
 1 files changed, 18 insertions(+), 5 deletions(-)

diff --git a/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java b/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
index 0c984e1..e23adc2 100644
--- a/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
+++ b/opends/src/server/org/opends/server/extensions/ConfigFileHandler.java
@@ -768,11 +768,12 @@
   private byte[] calculateConfigDigest()
           throws DirectoryException
   {
+    InputStream inputStream = null;
     try
     {
       MessageDigest sha1Digest =
            MessageDigest.getInstance(MESSAGE_DIGEST_ALGORITHM_SHA_1);
-      FileInputStream inputStream = new FileInputStream(configFile);
+      inputStream = new FileInputStream(configFile);
       byte[] buffer = new byte[8192];
       while (true)
       {
@@ -784,7 +785,6 @@
 
         sha1Digest.update(buffer, 0, bytesRead);
       }
-
       return sha1Digest.digest();
     }
     catch (Exception e)
@@ -795,6 +795,19 @@
       throw new DirectoryException(DirectoryServer.getServerErrorResultCode(),
                                    message, msgID, e);
     }
+    finally
+    {
+      if (inputStream != null)
+      {
+        try
+        {
+          inputStream.close();
+        }
+        catch (IOException e) {
+          // ignore;
+        }
+      }
+    }
   }
 
 
@@ -2030,9 +2043,9 @@
     // Delete the previous version of the configuration and rename the new one.
     try
     {
-      File f = new File(configFile);
-      f.delete();
-      new File(tempConfig).renameTo(f);
+      File actualConfig = new File(configFile);
+      File tmpConfig = new File(tempConfig);
+      renameFile(tmpConfig, actualConfig);
     }
     catch (Exception e)
     {

--
Gitblit v1.10.0