Blame SOURCES/0044-Issue-50572-After-running-cl-dump-dbdir-cldb-ldif.do.patch

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