mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 16:34:14 +08:00
mdbx-tools: refine/fix quiet
mode.
This commit is contained in:
parent
dc9869f1a1
commit
9746dd20df
@ -79,11 +79,12 @@ int main(int argc, char *argv[]) {
|
|||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
usage();
|
usage();
|
||||||
|
|
||||||
/* -d: delete the db, don't just empty it
|
while ((i = getopt(argc, argv,
|
||||||
* -s: drop the named subDB
|
"d"
|
||||||
* -V: print version and exit
|
"s:"
|
||||||
* (default) empty the main DB */
|
"n"
|
||||||
while ((i = getopt(argc, argv, "ds:nV")) != EOF) {
|
"q"
|
||||||
|
"V")) != EOF) {
|
||||||
switch (i) {
|
switch (i) {
|
||||||
case 'V':
|
case 'V':
|
||||||
printf("mdbx_drop version %d.%d.%d.%d\n"
|
printf("mdbx_drop version %d.%d.%d.%d\n"
|
||||||
@ -99,6 +100,9 @@ int main(int argc, char *argv[]) {
|
|||||||
mdbx_build.target, mdbx_build.compiler, mdbx_build.flags,
|
mdbx_build.target, mdbx_build.compiler, mdbx_build.flags,
|
||||||
mdbx_build.options);
|
mdbx_build.options);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
case 'q':
|
||||||
|
quiet = true;
|
||||||
|
break;
|
||||||
case 'd':
|
case 'd':
|
||||||
delete = true;
|
delete = true;
|
||||||
break;
|
break;
|
||||||
@ -130,11 +134,12 @@ int main(int argc, char *argv[]) {
|
|||||||
#endif /* !WINDOWS */
|
#endif /* !WINDOWS */
|
||||||
|
|
||||||
envname = argv[optind];
|
envname = argv[optind];
|
||||||
if (!quiet)
|
if (!quiet) {
|
||||||
printf("mdbx_drop %s (%s, T-%s)\nRunning for %s/%s...\n",
|
printf("mdbx_drop %s (%s, T-%s)\nRunning for %s/%s...\n",
|
||||||
mdbx_version.git.describe, mdbx_version.git.datetime,
|
mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||||
mdbx_version.git.tree, envname, subname ? subname : "@MAIN");
|
mdbx_version.git.tree, envname, subname ? subname : "@MAIN");
|
||||||
fflush(nullptr);
|
fflush(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
rc = mdbx_env_create(&env);
|
rc = mdbx_env_create(&env);
|
||||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||||
|
@ -101,7 +101,9 @@ static void dumpval(MDBX_val *v) {
|
|||||||
bool quiet = false, rescue = false;
|
bool quiet = false, rescue = false;
|
||||||
const char *prog;
|
const char *prog;
|
||||||
static void error(const char *func, int rc) {
|
static void error(const char *func, int rc) {
|
||||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc, mdbx_strerror(rc));
|
if (!quiet)
|
||||||
|
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc,
|
||||||
|
mdbx_strerror(rc));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Dump in BDB-compatible format */
|
/* Dump in BDB-compatible format */
|
||||||
@ -216,7 +218,7 @@ static int dump_sdb(MDBX_txn *txn, MDBX_dbi dbi, char *name) {
|
|||||||
|
|
||||||
static void usage(void) {
|
static void usage(void) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: %s [-V] [-q] [-f file] [-l] [-p] [-a|-s subdb] [-r] "
|
"usage: %s [-V] [-q] [-f file] [-l] [-p] [-r] [-a|-s subdb] "
|
||||||
"dbpath\n"
|
"dbpath\n"
|
||||||
" -V\t\tprint version and exit\n"
|
" -V\t\tprint version and exit\n"
|
||||||
" -q\t\tbe quiet\n"
|
" -q\t\tbe quiet\n"
|
||||||
@ -431,8 +433,9 @@ int main(int argc, char *argv[]) {
|
|||||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||||
if (!rescue)
|
if (!rescue)
|
||||||
break;
|
break;
|
||||||
fprintf(stderr, "%s: %s: ignore %s for `%s` and continue\n", prog,
|
if (!quiet)
|
||||||
envname, mdbx_strerror(rc), subname);
|
fprintf(stderr, "%s: %s: ignore %s for `%s` and continue\n", prog,
|
||||||
|
envname, mdbx_strerror(rc), subname);
|
||||||
/* Here is a hack for rescue mode, don't do that:
|
/* Here is a hack for rescue mode, don't do that:
|
||||||
* - we should restart transaction in case error due
|
* - we should restart transaction in case error due
|
||||||
* database corruption;
|
* database corruption;
|
||||||
@ -466,8 +469,9 @@ int main(int argc, char *argv[]) {
|
|||||||
if (have_raw && (!count /* || rescue */))
|
if (have_raw && (!count /* || rescue */))
|
||||||
rc = dump_sdb(txn, MAIN_DBI, nullptr);
|
rc = dump_sdb(txn, MAIN_DBI, nullptr);
|
||||||
else if (!count) {
|
else if (!count) {
|
||||||
fprintf(stderr, "%s: %s does not contain multiple databases\n", prog,
|
if (!quiet)
|
||||||
envname);
|
fprintf(stderr, "%s: %s does not contain multiple databases\n", prog,
|
||||||
|
envname);
|
||||||
rc = MDBX_NOTFOUND;
|
rc = MDBX_NOTFOUND;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -480,7 +484,8 @@ int main(int argc, char *argv[]) {
|
|||||||
case MDBX_SUCCESS:
|
case MDBX_SUCCESS:
|
||||||
break;
|
break;
|
||||||
case MDBX_EINTR:
|
case MDBX_EINTR:
|
||||||
fprintf(stderr, "Interrupted by signal/user\n");
|
if (!quiet)
|
||||||
|
fprintf(stderr, "Interrupted by signal/user\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
|
@ -54,8 +54,9 @@ static void print_stat(MDBX_stat *ms) {
|
|||||||
|
|
||||||
static void usage(const char *prog) {
|
static void usage(const char *prog) {
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"usage: %s [-V] [-e] [-f[f[f]]] [-r[r]] [-a|-s name] dbpath\n"
|
"usage: %s [-V] [-q] [-e] [-f[f[f]]] [-r[r]] [-a|-s name] dbpath\n"
|
||||||
" -V\t\tprint version and exit\n"
|
" -V\t\tprint version and exit\n"
|
||||||
|
" -q\t\tbe quiet\n"
|
||||||
" -e\t\tshow whole DB info\n"
|
" -e\t\tshow whole DB info\n"
|
||||||
" -f\t\tshow GC info\n"
|
" -f\t\tshow GC info\n"
|
||||||
" -r\t\tshow readers\n"
|
" -r\t\tshow readers\n"
|
||||||
@ -88,8 +89,11 @@ static int reader_list_func(void *ctx, int num, int slot, mdbx_pid_t pid,
|
|||||||
}
|
}
|
||||||
|
|
||||||
const char *prog;
|
const char *prog;
|
||||||
|
bool quiet = false;
|
||||||
static void error(const char *func, int rc) {
|
static void error(const char *func, int rc) {
|
||||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc, mdbx_strerror(rc));
|
if (!quiet)
|
||||||
|
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc,
|
||||||
|
mdbx_strerror(rc));
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
@ -108,6 +112,7 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
while ((o = getopt(argc, argv,
|
while ((o = getopt(argc, argv,
|
||||||
"V"
|
"V"
|
||||||
|
"q"
|
||||||
"a"
|
"a"
|
||||||
"e"
|
"e"
|
||||||
"f"
|
"f"
|
||||||
@ -129,6 +134,9 @@ int main(int argc, char *argv[]) {
|
|||||||
mdbx_build.target, mdbx_build.compiler, mdbx_build.flags,
|
mdbx_build.target, mdbx_build.compiler, mdbx_build.flags,
|
||||||
mdbx_build.options);
|
mdbx_build.options);
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
|
case 'q':
|
||||||
|
quiet = true;
|
||||||
|
break;
|
||||||
case 'a':
|
case 'a':
|
||||||
if (subname)
|
if (subname)
|
||||||
usage(prog);
|
usage(prog);
|
||||||
@ -174,10 +182,12 @@ int main(int argc, char *argv[]) {
|
|||||||
|
|
||||||
envname = argv[optind];
|
envname = argv[optind];
|
||||||
envname = argv[optind];
|
envname = argv[optind];
|
||||||
printf("mdbx_stat %s (%s, T-%s)\nRunning for %s...\n",
|
if (!quiet) {
|
||||||
mdbx_version.git.describe, mdbx_version.git.datetime,
|
printf("mdbx_stat %s (%s, T-%s)\nRunning for %s...\n",
|
||||||
mdbx_version.git.tree, envname);
|
mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||||
fflush(nullptr);
|
mdbx_version.git.tree, envname);
|
||||||
|
fflush(nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
rc = mdbx_env_create(&env);
|
rc = mdbx_env_create(&env);
|
||||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||||
@ -356,7 +366,8 @@ int main(int argc, char *argv[]) {
|
|||||||
case MDBX_NOTFOUND:
|
case MDBX_NOTFOUND:
|
||||||
break;
|
break;
|
||||||
case MDBX_EINTR:
|
case MDBX_EINTR:
|
||||||
fprintf(stderr, "Interrupted by signal/user\n");
|
if (!quiet)
|
||||||
|
fprintf(stderr, "Interrupted by signal/user\n");
|
||||||
goto txn_abort;
|
goto txn_abort;
|
||||||
default:
|
default:
|
||||||
error("mdbx_cursor_get", rc);
|
error("mdbx_cursor_get", rc);
|
||||||
@ -462,7 +473,8 @@ int main(int argc, char *argv[]) {
|
|||||||
case MDBX_NOTFOUND:
|
case MDBX_NOTFOUND:
|
||||||
break;
|
break;
|
||||||
case MDBX_EINTR:
|
case MDBX_EINTR:
|
||||||
fprintf(stderr, "Interrupted by signal/user\n");
|
if (!quiet)
|
||||||
|
fprintf(stderr, "Interrupted by signal/user\n");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user