From d79ffa0d51c8de927346b74bb413d1f1455d4028 Mon Sep 17 00:00:00 2001
From: neil_a_wilson <neil_a_wilson@localhost>
Date: Tue, 13 Feb 2007 01:37:52 +0000
Subject: [PATCH] Fix a bug in the LDIFDiff tool that could cause it to miss added or deleted entries under certain conditions.  Also, add a number of test cases to cover the LDIFDiff tool.

---
 opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java |  109 +++++++++++++++++++++++++++++-------------------------
 1 files changed, 58 insertions(+), 51 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java
index 979adca..e00f2b1 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDIFModify.java
@@ -22,7 +22,7 @@
  * CDDL HEADER END
  *
  *
- *      Portions Copyright 2006 Sun Microsystems, Inc.
+ *      Portions Copyright 2006-2007 Sun Microsystems, Inc.
  */
 package org.opends.server.tools;
 
@@ -394,7 +394,7 @@
    */
   public static void main(String[] args)
   {
-    int returnCode = ldifModifyMain(args);
+    int returnCode = ldifModifyMain(args, false);
     if (returnCode != 0)
     {
       System.exit(returnCode);
@@ -407,12 +407,16 @@
    * Processes the command-line arguments and makes the appropriate updates to
    * the LDIF file.
    *
-   * @param  args  The command-line arguments provided to the client.
+   * @param  args               The command line arguments provided to this
+   *                            program.
+   * @param  serverInitialized  Indicates whether the Directory Server has
+   *                            already been initialized (and therefore should
+   *                            not be initialized a second time).
    *
    * @return  A value of zero if everything completed properly, or nonzero if
    *          any problem(s) occurred.
    */
-  public static int ldifModifyMain(String[] args)
+  public static int ldifModifyMain(String[] args, boolean serverInitialized)
   {
     // Prepare the argument parser.
     BooleanArgument showUsage;
@@ -498,57 +502,60 @@
     }
 
 
-    // Bootstrap the Directory Server configuration for use as a client.
-    DirectoryServer directoryServer = DirectoryServer.getInstance();
-    directoryServer.bootstrapClient();
-
-
-    // If we're to use the configuration then initialize it, along with the
-    // schema.
-    boolean checkSchema = configFile.isPresent();
-    if (checkSchema)
+    if (! serverInitialized)
     {
-      try
-      {
-        directoryServer.initializeJMX();
-      }
-      catch (Exception e)
-      {
-        int    msgID   = MSGID_LDIFMODIFY_CANNOT_INITIALIZE_JMX;
-        String message = getMessage(msgID,
-                                    String.valueOf(configFile.getValue()),
-                                    e.getMessage());
-        System.err.println(message);
-        return 1;
-      }
+      // Bootstrap the Directory Server configuration for use as a client.
+      DirectoryServer directoryServer = DirectoryServer.getInstance();
+      directoryServer.bootstrapClient();
 
-      try
-      {
-        directoryServer.initializeConfiguration(configClass.getValue(),
-                                                configFile.getValue());
-      }
-      catch (Exception e)
-      {
-        int    msgID   = MSGID_LDIFMODIFY_CANNOT_INITIALIZE_CONFIG;
-        String message = getMessage(msgID,
-                                    String.valueOf(configFile.getValue()),
-                                    e.getMessage());
-        System.err.println(message);
-        return 1;
-      }
 
-      try
+      // If we're to use the configuration then initialize it, along with the
+      // schema.
+      boolean checkSchema = configFile.isPresent();
+      if (checkSchema)
       {
-        directoryServer.initializeSchema();
-      }
-      catch (Exception e)
-      {
-        int    msgID   = MSGID_LDIFMODIFY_CANNOT_INITIALIZE_SCHEMA;
-        String message = getMessage(msgID,
-                                    String.valueOf(configFile.getValue()),
-                                    e.getMessage());
-        System.err.println(message);
-        return 1;
+        try
+        {
+          directoryServer.initializeJMX();
+        }
+        catch (Exception e)
+        {
+          int    msgID   = MSGID_LDIFMODIFY_CANNOT_INITIALIZE_JMX;
+          String message = getMessage(msgID,
+                                      String.valueOf(configFile.getValue()),
+                                      e.getMessage());
+          System.err.println(message);
+          return 1;
+        }
+
+        try
+        {
+          directoryServer.initializeConfiguration(configClass.getValue(),
+                                                  configFile.getValue());
+        }
+        catch (Exception e)
+        {
+          int    msgID   = MSGID_LDIFMODIFY_CANNOT_INITIALIZE_CONFIG;
+          String message = getMessage(msgID,
+                                      String.valueOf(configFile.getValue()),
+                                      e.getMessage());
+          System.err.println(message);
+          return 1;
+        }
+
+        try
+        {
+          directoryServer.initializeSchema();
+        }
+        catch (Exception e)
+        {
+          int    msgID   = MSGID_LDIFMODIFY_CANNOT_INITIALIZE_SCHEMA;
+          String message = getMessage(msgID,
+                                      String.valueOf(configFile.getValue()),
+                                      e.getMessage());
+          System.err.println(message);
+          return 1;
+        }
       }
     }
 

--
Gitblit v1.10.0