29 #ifdef XAPIAN_HAS_GLASS_BACKEND
37 #ifdef XAPIAN_HAS_HONEY_BACKEND
50 #include <string_view>
54 #ifdef XAPIAN_HAS_GLASS_BACKEND
67 #ifdef XAPIAN_HAS_HONEY_BACKEND
84 auto msg =
"Couldn't find Xapian database or table to check";
92 #if defined XAPIAN_HAS_GLASS_BACKEND
100 *out <<
"Cross-checking document lengths between the postlist and "
101 "termlist tables would use more than 1GB of memory, so "
102 "skipping that check" << endl;
106 doclens.reserve(last_docid + 1);
107 }
catch (
const std::bad_alloc &) {
110 *out <<
"Couldn't allocate enough memory for cross-checking document "
111 "lengths between the postlist and termlist tables, so "
112 "skipping that check" << endl;
113 }
catch (
const std::length_error &) {
116 *out <<
"Couldn't allocate enough elements for cross-checking document "
117 "lengths between the postlist and termlist tables, so "
118 "skipping that check" << endl;
127 string filename{path};
128 filename +=
"/iamglass";
129 if (stat(filename.c_str(), &sb) == 0) {
130 #ifndef XAPIAN_HAS_GLASS_BACKEND
136 vector<Xapian::termcount> doclens;
145 *out <<
"Database couldn't be opened for reading: "
147 <<
"\nContinuing check anyway" << endl;
153 for (
auto r = version_file.
get_revision(); r != 0; --r) {
154 filename.resize(path.size());
155 filename +=
"/changes";
165 *out <<
"last_docid = " << db_last_docid <<
" < doccount = "
180 filename.resize(path.size());
181 filename +=
"/iamhoney";
182 if (stat(filename.c_str(), &sb) == 0) {
183 #ifndef XAPIAN_HAS_HONEY_BACKEND
186 auto msg =
"Honey database support isn't enabled";
190 vector<Xapian::termcount> doclens;
199 *out <<
"Database couldn't be opened for reading: "
201 <<
"\nContinuing check anyway" << endl;
208 for (
auto r = version_file.
get_revision(); r != 0; --r) {
209 string changes_file = path;
210 changes_file +=
"/changes";
211 changes_file +=
str(r);
213 HoneyChanges::check(changes_file);
221 *out <<
"last_docid = " << db_last_docid <<
" < doccount = "
236 filename.resize(path.size());
237 filename +=
"/iamchert";
238 if (stat(filename.c_str(), &sb) == 0) {
243 filename.resize(path.size());
244 filename +=
"/iamflint";
245 if (stat(filename.c_str(), &sb) == 0) {
250 filename.resize(path.size());
251 filename +=
"/iambrass";
252 if (stat(filename.c_str(), &sb) == 0) {
257 filename.resize(path.size());
258 filename +=
"/record_DB";
259 if (stat(filename.c_str(), &sb) == 0) {
265 "Directory does not contain a Xapian database");
278 size_t p = filename.find_last_of(
DIR_SEPS);
284 string dir(filename, 0,
p);
287 while (
p != filename.size()) {
288 char ch = filename[
p++];
289 if (ch ==
'.')
break;
293 #if defined XAPIAN_HAS_GLASS_BACKEND
294 vector<Xapian::termcount> doclens;
302 #ifndef XAPIAN_HAS_GLASS_BACKEND
303 auto msg =
"Glass database support isn't enabled";
314 #ifndef XAPIAN_HAS_HONEY_BACKEND
315 auto msg =
"Honey database support isn't enabled";
336 if (stat((dir +
"/iamchert").c_str(), &sb) == 0) {
340 if (stat((dir +
"/iamflint").c_str(), &sb) == 0) {
344 if (stat((dir +
"/iambrass").c_str(), &sb) == 0) {
368 #ifdef XAPIAN_HAS_GLASS_BACKEND
377 *out <<
"last_docid = " << db_last_docid <<
" < doccount = "
381 vector<Xapian::termcount> doclens;
387 version_file,
opts, doclens,
399 #ifdef XAPIAN_HAS_HONEY_BACKEND
423 [&errors,
opts, out](string_view path) {
424 errors += Database::check(path,
opts, out);
426 [&errors,
opts, out](string_view path) {
428 errors += Database::check(path,
opts, out);
430 [&errors,
opts, out](string_view path) {
432 errors += Database::check(path,
opts, out);
434 [](string_view, string_view) {
435 auto msg =
"Remote database checking not implemented";
438 [](string_view, unsigned) {
439 auto msg =
"Remote database checking not implemented";
443 auto msg =
"InMemory database checking not implemented";
450 Database::check_(
const string_view* path_ptr,
461 if (path_ptr == NULL) {
465 if (path_ptr->empty()) {
469 string filename{*path_ptr};
471 if (stat(filename.c_str(), &sb) == 0) {
504 filename.resize(filename.size() - 1);
508 if (stat((filename +
".DB").c_str(), &sb) == 0) {
static size_t check_db_dir(string_view path, int opts, std::ostream *out)
static void throw_no_db_to_check()
static const struct @5 honey_tables[]
static void reserve_doclens(vector< Xapian::termcount > &doclens, Xapian::docid last_docid, ostream *out)
static size_t check_db_fd(int fd, int opts, std::ostream *out, int backend)
Check a single file DB from an fd.
static size_t check_db_table(string_view filename, int opts, std::ostream *out, int backend)
Check a database table.
static const struct @4 glass_tables[]
static void check(const std::string &changes_file)
The GlassVersion class manages the revision files.
Xapian::docid get_last_docid() const
glass_revision_number_t get_revision() const
Xapian::doccount get_doccount() const
void read()
Read the version file and check it's a version we understand.
The HoneyVersion class manages the revision files.
Xapian::docid get_last_docid() const
honey_revision_number_t get_revision() const
void read()
Read the version file and check it's a version we understand.
Xapian::doccount get_doccount() const
DatabaseOpeningError indicates failure to open a database.
An indexed database of documents.
All exceptions thrown by Xapian are subclasses of Xapian::Error.
std::string get_description() const
Return a string describing this object.
Indicates an attempt to use a feature which is unavailable.
UnimplementedError indicates an attempt to use an unimplemented feature.
Constants in the Xapian namespace.
An indexed database of documents.
int test_if_single_file_db(int fd)
Probe if a file descriptor is a single-file database.
Helper functions for database handling.
void read_stub_file(std::string_view file, A1 action_auto, A2 action_glass, A3 action_honey, A4 action_remote_prog, A5 action_remote_tcp, A6 action_inmemory)
Open, read and process a stub database file.
Hierarchy of classes which Xapian can throw as exceptions.
Utility functions for testing files.
bool file_exists(const char *path)
Test if a file exists.
size_t check_glass_table(const char *tablename, string_view db_dir, int fd, off_t offset_, const GlassVersion &version_file, int opts, vector< Xapian::termcount > &doclens, ostream *out)
Definitions, types, etc for use inside glass.
#define GLASS_TABLE_EXTENSION
Glass table extension.
size_t check_honey_table(const char *tablename, string_view db_dir, int fd, off_t offset_, const HoneyVersion &version_file, int opts, vector< Xapian::termcount > &doclens, ostream *out)
Definitions, types, etc for use inside honey.
#define HONEY_TABLE_EXTENSION
Honey table extension.
string str(int value)
Convert int to std::string.
The Xapian namespace contains public interfaces for the Xapian library.
unsigned XAPIAN_TERMCOUNT_BASE_TYPE termcount
A counts of terms.
const int DBCHECK_FIX
Fix problems.
static size_t check_stub(const string &stub_path, int opts, std::ostream *out)
unsigned XAPIAN_DOCID_BASE_TYPE doccount
A count of documents.
unsigned XAPIAN_DOCID_BASE_TYPE docid
A unique identifier for a document.
Various assertion macros.
Various handy string-related helpers.
bool endswith(std::string_view s, char sfx)