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

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