Blob Blame History Raw
From d8935139d377ad75be4242db7d3194f3706dc44a Mon Sep 17 00:00:00 2001
From: Simon Pichugin <spichugi@redhat.com>
Date: Thu, 29 Aug 2019 15:51:56 +0200
Subject: [PATCH] Issue 50572 - After running cl-dump dbdir/cldb/*ldif.done are
 not deleted

Description: By default, remove ldif.done files after running cl-dump.
Add an option '-l' which allows keep the files.
Update man files.

https://pagure.io/389-ds-base/issue/50572

Reviewed by: firstyear, mreynolds (Thanks!)
---
 ldap/admin/src/scripts/cl-dump.pl | 23 +++++++++++++++--------
 man/man1/cl-dump.1                | 11 +++++++----
 2 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/ldap/admin/src/scripts/cl-dump.pl b/ldap/admin/src/scripts/cl-dump.pl
index f4ad5dd33..2e7f20413 100755
--- a/ldap/admin/src/scripts/cl-dump.pl
+++ b/ldap/admin/src/scripts/cl-dump.pl
@@ -5,7 +5,7 @@
 # All rights reserved.
 #
 # License: GPL (version 3 or any later version).
-# See LICENSE for details. 
+# See LICENSE for details.
 # END COPYRIGHT BLOCK
 ###################################################################################
 #
@@ -13,7 +13,7 @@
 #
 # SYNOPSIS:
 #  cl-dump.pl [-h host] [-p port] [-D bind-dn] -w bind-password | -P bind-cert
-#       [-r replica-roots] [-o output-file] [-c] [-v]
+#       [-r replica-roots] [-o output-file] [-c] [-l] [-v]
 #
 #  cl-dump.pl -i changelog-ldif-file-with-base64encoding [-o output-file] [-c]
 #
@@ -22,7 +22,7 @@
 #
 # OPTIONS:
 #    -c Dump and interpret CSN only. This option can be used with or
-#       without -i option. 
+#       without -i option.
 #
 #    -D bind-dn
 #       Directory server's bind DN. Default to "cn=Directory Manager" if
@@ -32,6 +32,8 @@
 #       Directory server's host. Default to the server where the script
 #       is running.
 #
+#    -l Preserve generated ldif.done files from changelogdir
+#
 #    -i changelog-ldif-file-with-base64encoding
 #       If you already have a ldif-like changelog, but the changes
 #       in that file are encoded, you may use this option to
@@ -68,7 +70,7 @@
 # all of this nonsense can be omitted if the mozldapsdk and perldap are
 # installed in the operating system locations (e.g. /usr/lib /usr/lib/perl5)
 
-$usage="Usage: $0 [-h host] [-p port] [-D bind-dn] [-w bind-password | -P bind-cert] [-r replica-roots] [-o output-file] [-c] [-v]\n\n       $0 -i changelog-ldif-file-with-base64encoding [-o output-file] [-c]\n";
+$usage="Usage: $0 [-h host] [-p port] [-D bind-dn] [-w bind-password | -P bind-cert] [-r replica-roots] [-o output-file] [-c] [-l] [-v]\n\n       $0 -i changelog-ldif-file-with-base64encoding [-o output-file] [-c]\n";
 
 use Getopt::Std;			# Parse command line arguments
 use Mozilla::LDAP::Conn;		# LDAP module for Perl
@@ -86,7 +88,7 @@ $version = "Directory Server Changelog Dump - Version 1.0";
 	$| = 1;
 
 	# Check for legal options
-	if (!getopts('h:p:D:w:P:r:o:cvi:')) {
+	if (!getopts('h:p:D:w:P:r:o:clvi:')) {
 		print $usage;
 		exit -1;
 	}
@@ -123,7 +125,7 @@ sub validateArgs
 	if ($opt_o && ! open (OUTPUT, ">$opt_o")) {
 		print "Can't create output file $opt_o\n";
 		$rc = -1;
-	} 
+	}
 	# Open STDOUT if option -o is missing
 	open (OUTPUT, ">-") if !$opt_o;
 
@@ -194,10 +196,15 @@ sub cl_dump_and_decode
 			else {
 				&cl_decode ($_);
 			}
-			# Test op -M doesn't work well so we use rename
+			# Test op -M doesn't work well so we use rename/remove
 			# here to avoid reading the same ldif file more
 			# than once.
-			rename ($ldif, "$ldif.done");
+			if ($opt_l) {
+				rename ($ldif, "$ldif.done");
+			} else {
+				# Remove the file - default behaviou when '-l' is not specified
+				unlink ($ldif)
+			}
 		}
 		&print_header ($replica, "Not Found") if !$gotldif;
 	}
diff --git a/man/man1/cl-dump.1 b/man/man1/cl-dump.1
index db736aca9..fbb836a72 100644
--- a/man/man1/cl-dump.1
+++ b/man/man1/cl-dump.1
@@ -20,7 +20,7 @@ cl-dump \- Dump and decode Directory Server replication change log
 .SH SYNOPSIS
 .B cl\-dump
 [\fI\-h host\fR] [\fI\-p port\fR] [\fI\-D bind\(hydn\fR] \-w bind\(hypassword | \-P bind\(hycert
-       [\fI\-r replica\(hyroots\fR] [\fI\-o output\(hyfile\fR] [\fI\-c\fR] [\fI\-v\fR]
+       [\fI\-r replica\(hyroots\fR] [\fI\-o output\(hyfile\fR] [\fI\-c\fR] [\fI\-l\fR] [\fI\-v\fR]
 
 .PP
 .B cl\-dump
@@ -30,12 +30,12 @@ cl-dump \- Dump and decode Directory Server replication change log
 Dump and decode Directory Server replication change log
 .PP
 .\" TeX users may be more comfortable with the \fB<whatever>\fP and
-.\" \fI<whatever>\fP escape sequences to invode bold face and italics, 
+.\" \fI<whatever>\fP escape sequences to invode bold face and italics,
 .\" respectively.
 .SH OPTIONS
 A summary of options is included below.
 .TP
-.B \-c 
+.B \-c
 Dump and interpret CSN only. This option can be used with or
 without \-i option.
 .TP
@@ -47,6 +47,9 @@ the option is omitted.
 Directory server's host. Default to the server where the script
 is running.
 .TP
+.B \-l
+Preserve generated ldif.done files from changelogdir
+.TP
 .B \-i changelog\(hyldif\(hyfile\(hywith\(hybase64encoding
 If you already have a ldif-like changelog, but the changes
 in that file are encoded, you may use this option to
@@ -66,7 +69,7 @@ Specify replica roots whose changelog you want to dump. The replica
 roots may be separated by comma. All the replica roots would be
 dumped if the option is omitted.
 .TP
-.B \-v 
+.B \-v
 Print the version of this script.
 .TP
 .B \-w bind\(hypassword
-- 
2.21.0