summaryrefslogtreecommitdiff
path: root/utilities/db_verify/util_verify.c
blob: 5c5bd02407f7153cee1ade77016c29ab0f4fcdb9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
 * See the file LICENSE for redistribution information.
 *
 * Copyright (c) 2009 WiredTiger Software.
 *	All rights reserved.
 *
 * $Id$
 */

#include "wt_internal.h"
#include "util.h"

const char *progname;

int	usage(void);

int
main(int argc, char *argv[])
{
	extern char *optarg;
	extern int optind;
	DB *db;
	int ch, ret, tret, verbose;

	WT_UTILITY_INTRO(progname, argv);

	verbose = 0;
	while ((ch = getopt(argc, argv, "Vv")) != EOF)
		switch (ch) {
		case 'v':			/* verbose */
			verbose = 1;
			break;
		case 'V':			/* version */
			printf("%s\n", wiredtiger_version(NULL, NULL, NULL));
			return (EXIT_SUCCESS);
		case '?':
		default:
			return (usage());
		}
	argc -= optind;
	argv += optind;

	/* The remaining argument is the database name. */
	if (argc != 1)
		return (usage());

	if ((ret = wiredtiger_simple_setup(progname, &db, 0, 0)) == 0) {
		if ((ret = db->open(db, *argv, 0, 0)) != 0) {
			db->err(db, ret, "Db.open: %s", *argv);
			goto err;
		}
		if ((ret =
		    db->verify(db, verbose ? __wt_progress : NULL, 0)) != 0) {
			db->err(db, ret, "Db.verify: %s", *argv);
			goto err;
		}
		if (verbose)
			printf("\n");
	}

	if (0) {
err:		ret = 1;
	}
	if ((tret = wiredtiger_simple_teardown(progname, db)) != 0 && ret == 0)
		ret = tret;
	return (ret == 0 ? EXIT_SUCCESS : EXIT_FAILURE);
}

int
usage()
{
	(void)fprintf(stderr, "usage: %s [-Vv] database\n", progname);
	return (EXIT_FAILURE);
}