From 583613ae94d73e8044bc401008b16b22d23db865 Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 08 Apr 2009 10:21:29 +0000
Subject: [PATCH] Fix for issue 2764 (ldapsearch: "--countEntries" option, the number of matching entries should not be used as return code) --This line, and th se below, will be ignored--

---
 opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java |   34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)

diff --git a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
index a123fed..2d029e8 100644
--- a/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
+++ b/opendj-sdk/opends/src/server/org/opends/server/tools/LDAPSearch.java
@@ -553,7 +553,7 @@
 
   public static void main(String[] args)
   {
-    int retCode = mainSearch(args, true, System.out, System.err);
+    int retCode = mainSearch(args, true, false, System.out, System.err);
 
     if(retCode != 0)
     {
@@ -572,7 +572,7 @@
 
   public static int mainSearch(String[] args)
   {
-    return mainSearch(args, true, System.out, System.err);
+    return mainSearch(args, true, true, System.out, System.err);
   }
 
   /**
@@ -591,10 +591,36 @@
    *
    * @return The error code.
    */
-
   public static int mainSearch(String[] args, boolean initializeServer,
                                OutputStream outStream, OutputStream errStream)
   {
+    return mainSearch(args, initializeServer, true, outStream, errStream);
+  }
+
+  /**
+   * Parses the provided command-line arguments and uses that information to
+   * run the ldapsearch tool.
+   *
+   * @param  args              The command-line arguments provided to this
+   *                           program.
+   * @param  initializeServer  Indicates whether to initialize the server.
+   * @param  returnMatchingEntries whether when the option --countEntries is
+   *                           specified, the number of matching entries should
+   *                           be returned or not.
+   * @param  outStream         The output stream to use for standard output, or
+   *                           <CODE>null</CODE> if standard output is not
+   *                           needed.
+   * @param  errStream         The output stream to use for standard error, or
+   *                           <CODE>null</CODE> if standard error is not
+   *                           needed.
+   *
+   * @return The error code.
+   */
+
+  public static int mainSearch(String[] args, boolean initializeServer,
+      boolean returnMatchingEntries, OutputStream outStream,
+      OutputStream errStream)
+  {
     PrintStream out;
     if (outStream == null)
     {
@@ -1759,7 +1785,7 @@
                                                    searchOptions, wrapColumn);
       }
 
-      if (countEntries.isPresent())
+      if (countEntries.isPresent() && returnMatchingEntries)
       {
         return matchingEntries;
       }

--
Gitblit v1.10.0