2 * @brief Tool to check the consistency of a database or table.
4 /* Copyright 1999,2000,2001 BrightStation PLC
5 * Copyright 2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2014,2016 Olly Betts
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; either version 2 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
34 #define PROG_NAME "xapian-check"
35 #define PROG_DESC "Check the consistency of a database or table"
37 static void show_usage() {
38 cout
<< "Usage: " PROG_NAME
" DATABASE_DIRECTORY|PATH_TO_BTREE [[F][t][f][b][v][+]]\n\n"
39 "If a whole database is checked, then additional cross-checks between\n"
40 "the tables are performed.\n\n"
41 "The btree(s) is/are always checked - control the output verbosity with:\n"
42 " F = attempt to fix a broken database (implemented for glass currently)\n"
43 " t = short tree printing\n"
44 " f = full tree printing\n"
45 " b = show free blocks\n"
46 " v = show stats about B-tree (default)\n"
48 " e.g. " PROG_NAME
" /var/lib/xapian/data/default\n"
49 " " PROG_NAME
" /var/lib/xapian/data/default/postlist fbv\n";
53 main(int argc
, char **argv
)
55 if (argc
> 1 && argv
[1][0] == '-') {
56 if (strcmp(argv
[1], "--help") == 0) {
57 cout
<< PROG_NAME
" - " PROG_DESC
"\n\n";
61 if (strcmp(argv
[1], "--version") == 0) {
62 cout
<< PROG_NAME
" - " PACKAGE_STRING
"\n";
66 if (argc
< 2 || argc
> 3) {
72 const char * opt_string
= argv
[2];
73 if (!opt_string
) opt_string
= "v";
74 for (const char *p
= opt_string
; *p
; ++p
) {
76 case 't': opts
|= Xapian::DBCHECK_SHORT_TREE
; break;
77 case 'f': opts
|= Xapian::DBCHECK_FULL_TREE
; break;
78 case 'b': opts
|= Xapian::DBCHECK_SHOW_FREELIST
; break;
79 case 'v': opts
|= Xapian::DBCHECK_SHOW_STATS
; break;
81 opts
|= Xapian::DBCHECK_SHORT_TREE
;
82 opts
|= Xapian::DBCHECK_SHOW_FREELIST
;
83 opts
|= Xapian::DBCHECK_SHOW_STATS
;
86 opts
|= Xapian::DBCHECK_FIX
;
89 cerr
<< "option " << opt_string
<< " unknown\n";
90 cerr
<< "use t,f,b,v and/or + in the option string\n";
96 size_t errors
= Xapian::Database::check(argv
[1], opts
, &cout
);
98 cout
<< "Total errors found: " << errors
<< '\n';
101 cout
<< "No errors found\n";
102 } catch (const Xapian::Error
&error
) {
103 cerr
<< argv
[0] << ": " << error
.get_description() << '\n';
106 cerr
<< argv
[0] << ": Unknown exception\n";