[PATCH] A few cosmetic ones for dbwrap_tool

Volker Lendecke Volker.Lendecke at SerNet.DE
Mon Sep 3 14:56:39 UTC 2018


Hi!

Review appreciated!

Thanks, Volker

-- 
SerNet GmbH, Bahnhofsallee 1b, 37081 Göttingen
phone: +49-551-370000-0, fax: +49-551-370000-9
AG Göttingen, HRB 2816, GF: Dr. Johannes Loxen
http://www.sernet.de, mailto:kontakt at sernet.de

Meet us at Storage Developer Conference (SDC)
Santa Clara, CA USA, September 24th-27th 2018
-------------- next part --------------
From fdfdbf825d03251c6ed5f38c6d8c369c59abd3c0 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 24 Aug 2018 14:39:19 +0200
Subject: [PATCH 1/5] dbwrap_tool: Simplify dbwrap_tool_erase

That's what dbwrap_wipe is for :-)

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/utils/dbwrap_tool.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
index 94aacd8ba26..3ba0c52bb4c 100644
--- a/source3/utils/dbwrap_tool.c
+++ b/source3/utils/dbwrap_tool.c
@@ -280,13 +280,6 @@ static int dbwrap_tool_exists(struct db_context *db,
 	return (result)?0:1;
 }
 
-
-static int delete_fn(struct db_record *rec, void *priv)
-{
-	dbwrap_record_delete(rec);
-	return 0;
-}
-
 /**
  * dbwrap_tool_erase: erase the whole data base
  * the keyname argument is not used.
@@ -295,11 +288,11 @@ static int dbwrap_tool_erase(struct db_context *db,
 			     const char *keyname,
 			     const char *data)
 {
-	NTSTATUS status;
+	int ret;
 
-	status = dbwrap_traverse(db, delete_fn, NULL, NULL);
+	ret = dbwrap_wipe(db);
 
-	if (!NT_STATUS_IS_OK(status)) {
+	if (ret != 0) {
 		d_fprintf(stderr, "ERROR erasing the database\n");
 		return -1;
 	}
-- 
2.11.0


From ed731d8f00090099ef9e3ff3fa9a9dff1c9eae3d Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 24 Aug 2018 14:41:41 +0200
Subject: [PATCH 2/5] dbwrap_tool: Simplify listkey_fn

To me dbwrap_record_get_key(rec).dsize just looks a bit ugly

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/utils/dbwrap_tool.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
index 3ba0c52bb4c..ee08c2dc4b6 100644
--- a/source3/utils/dbwrap_tool.c
+++ b/source3/utils/dbwrap_tool.c
@@ -302,8 +302,9 @@ static int dbwrap_tool_erase(struct db_context *db,
 
 static int listkey_fn(struct db_record *rec, void *private_data)
 {
-	int length = dbwrap_record_get_key(rec).dsize;
-	unsigned char *p = (unsigned char *)dbwrap_record_get_key(rec).dptr;
+	TDB_DATA key = dbwrap_record_get_key(rec);
+	size_t length = key.dsize;
+	unsigned char *p = (unsigned char *)key.dptr;
 
 	while (length--) {
 		if (isprint(*p) && !strchr("\"\\", *p)) {
-- 
2.11.0


From fcfdb1db28b3338dbb4c71506d51fb7d00b38775 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 24 Aug 2018 15:06:34 +0200
Subject: [PATCH 3/5] dbwrap_tool: Simplify persistent/non-persistent check

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/utils/dbwrap_tool.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
index ee08c2dc4b6..09a27dbcb51 100644
--- a/source3/utils/dbwrap_tool.c
+++ b/source3/utils/dbwrap_tool.c
@@ -435,9 +435,7 @@ int main(int argc, const char **argv)
 		goto done;
 	}
 
-	if ((persistent == 0 && non_persistent == 0) ||
-	    (persistent == 1 && non_persistent == 1))
-	{
+	if ((persistent + non_persistent) != 1) {
 		d_fprintf(stderr, "ERROR: you must specify exactly one "
 			  "of --persistent and --non-persistent\n");
 		goto done;
-- 
2.11.0


From 6a7377ea60b7d8ed1bb32c09f75c7437a8fdfdf3 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 24 Aug 2018 15:07:28 +0200
Subject: [PATCH 4/5] dbwrap_tool: Avoid an unnecessary "else"

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/utils/dbwrap_tool.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
index 09a27dbcb51..5609b6c43d4 100644
--- a/source3/utils/dbwrap_tool.c
+++ b/source3/utils/dbwrap_tool.c
@@ -439,7 +439,8 @@ int main(int argc, const char **argv)
 		d_fprintf(stderr, "ERROR: you must specify exactly one "
 			  "of --persistent and --non-persistent\n");
 		goto done;
-	} else if (non_persistent == 1) {
+	}
+	if (non_persistent == 1) {
 		tdb_flags |= TDB_CLEAR_IF_FIRST;
 	}
 
-- 
2.11.0


From def7a02c170dfb75c621892c7c137b7c7023fda4 Mon Sep 17 00:00:00 2001
From: Volker Lendecke <vl at samba.org>
Date: Fri, 24 Aug 2018 15:11:53 +0200
Subject: [PATCH 5/5] dbwrap_tool: We don't do "listwatchers" anymore

Signed-off-by: Volker Lendecke <vl at samba.org>
---
 source3/utils/dbwrap_tool.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/source3/utils/dbwrap_tool.c b/source3/utils/dbwrap_tool.c
index 5609b6c43d4..9c27fdc1946 100644
--- a/source3/utils/dbwrap_tool.c
+++ b/source3/utils/dbwrap_tool.c
@@ -25,7 +25,6 @@
 #include "popt_common.h"
 #include "dbwrap/dbwrap.h"
 #include "dbwrap/dbwrap_open.h"
-#include "dbwrap/dbwrap_watch.h"
 #include "messages.h"
 #include "util_tdb.h"
 
@@ -429,7 +428,7 @@ int main(int argc, const char **argv)
 			  "USAGE: %s [options] <database> <op> [<key> [<type> "
 			  "[<value>]]]\n"
 			  "       ops: fetch, store, delete, exists, "
-			  "erase, listkeys, listwatchers\n"
+			  "erase, listkeys\n"
 			  "       types: int32, uint32, string, hex\n",
 			 argv[0]);
 		goto done;
@@ -501,7 +500,7 @@ int main(int argc, const char **argv)
 		d_fprintf(stderr,
 			  "ERROR: invalid op '%s' specified\n"
 			  "       supported ops: fetch, store, delete, exists, "
-			  "erase, listkeys, listwatchers\n",
+			  "erase, listkeys\n",
 			  opname);
 		goto done;
 	}
-- 
2.11.0



More information about the samba-technical mailing list