From 7d74aa6ae8b1e7651230663fd731b4511556fadc Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Wed, 27 Nov 2019 22:04:47 +0300 Subject: [PATCH] mdbx-load: add `-r` (rescue) and `-q` (quiet) options. Change-Id: I6dd8003a6f1c8b3fe7a25ce1f6cac3735a2c9734 --- src/tools/mdbx_load.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/tools/mdbx_load.c b/src/tools/mdbx_load.c index 00bfa87e..4d60fb32 100644 --- a/src/tools/mdbx_load.c +++ b/src/tools/mdbx_load.c @@ -327,6 +327,8 @@ int main(int argc, char *argv[]) { char *envname = NULL; int envflags = MDBX_UTTERLY_NOSYNC, putflags = 0; int append = 0; + int quiet = 0; + int rescue = 0; MDBX_val prevk; prog = argv[0]; @@ -341,7 +343,7 @@ int main(int argc, char *argv[]) { * -T: read plaintext * -V: print version and exit */ - while ((i = getopt(argc, argv, "af:ns:NTV")) != EOF) { + while ((i = getopt(argc, argv, "af:ns:NTVrq")) != EOF) { switch (i) { case 'V': printf("mdbx_load version %d.%d.%d.%d\n" @@ -379,6 +381,12 @@ int main(int argc, char *argv[]) { case 'T': mode |= NOHDR | PRINT; break; + case 'q': + quiet = 1; + break; + case 'r': + rescue = 1; + break; default: usage(); } @@ -401,9 +409,10 @@ int main(int argc, char *argv[]) { #endif /* !WINDOWS */ envname = argv[optind]; - printf("mdbx_load %s (%s, T-%s)\nRunning for %s...\n", - mdbx_version.git.describe, mdbx_version.git.datetime, - mdbx_version.git.tree, envname); + if (!quiet) + printf("mdbx_load %s (%s, T-%s)\nRunning for %s...\n", + mdbx_version.git.describe, mdbx_version.git.datetime, + mdbx_version.git.tree, envname); fflush(NULL); dbuf.iov_len = 4096; @@ -516,6 +525,11 @@ int main(int argc, char *argv[]) { rc = mdbx_cursor_put(mc, &key, &data, putflags | appflag); if (rc == MDBX_KEYEXIST && putflags) continue; + if (rc == MDBX_BAD_VALSIZE && rescue) { + fprintf(stderr, "%s: skip line %" PRIiSIZE ": due %s\n", prog, lineno, + mdbx_strerror(rc)); + continue; + } if (rc) { fprintf(stderr, "mdbx_cursor_put failed, error %d %s\n", rc, mdbx_strerror(rc));