From 9b0e980c54b4c50f85b5736b1fdcb60a473b818c 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.

---
 opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java |   41 +++++++++++++++++++++++++++++++++++++++++
 1 files changed, 41 insertions(+), 0 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java b/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java
index 0a9a3f8..58ffeb1 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/util/StaticUtils.java
@@ -59,6 +59,7 @@
 import org.opends.server.loggers.debug.DebugTracer;
 import org.opends.server.types.DebugLogLevel;
 import static org.opends.server.messages.MessageHandler.*;
+import static org.opends.server.messages.MessageHandler.getMessage;
 import static org.opends.server.messages.UtilityMessages.*;
 import static org.opends.server.util.ServerConstants.*;
 
@@ -3378,6 +3379,46 @@
     fileToMove.delete();
   }
 
+  /**
+   * Renames the source file to the target file.  If the target file exists
+   * it is first deleted.  The rename and delete operation return values
+   * are checked for success and if unsuccessful, this method throws an
+   * exception.
+   *
+   * @param fileToRename The file to rename.
+   * @param target       The file to which <code>fileToRename</code> will be
+   *                     moved.
+   * @throws IOException If a problem occurs while attempting to rename the
+   *                     file.  On the Windows platform, this typically
+   *                     indicates that the file is in use by this or another
+   *                     application.
+   */
+  static public void renameFile(File fileToRename, File target)
+          throws IOException {
+    if (fileToRename != null && target != null)
+    {
+      synchronized(target)
+      {
+        if (target.exists())
+        {
+          if (!target.delete())
+          {
+            int    msgID   = MSGID_RENAMEFILE_CANNOT_DELETE_TARGET;
+            String message = getMessage(msgID, target.getPath());
+            throw new IOException(message);
+          }
+        }
+      }
+      if (!fileToRename.renameTo(target))
+      {
+        int    msgID   = MSGID_RENAMEFILE_CANNOT_RENAME;
+        String message = getMessage(msgID, fileToRename.getPath(),
+                target.getPath());
+        throw new IOException(message);
+
+      }
+    }
+  }
 
 
   /**

--
Gitblit v1.10.0