22 #ifndef XAPIAN_INCLUDED_DATABASEHELPERS_H
23 #define XAPIAN_INCLUDED_DATABASEHELPERS_H
28 #include <string_view>
66 const std::string& path,
84 A4 action_remote_prog,
95 std::ifstream stub(std::string{file});
97 std::string msg =
"Couldn't open stub database file: ";
102 unsigned int line_no = 0;
103 while (std::getline(stub, line)) {
105 if (line.empty() || line[0] ==
'#')
107 std::string::size_type space = line.find(
' ');
108 if (space == std::string::npos) space = line.size();
110 std::string type(line, 0, space);
111 line.erase(0, space + 1);
113 if (type ==
"auto") {
119 if (type ==
"glass") {
120 #ifdef XAPIAN_HAS_GLASS_BACKEND
130 if (type ==
"honey") {
131 #ifdef XAPIAN_HAS_HONEY_BACKEND
141 if (type ==
"remote" && !line.empty()) {
142 #ifdef XAPIAN_HAS_REMOTE_BACKEND
143 if (line[0] ==
':') {
146 space = line.find(
' ');
148 if (space == std::string::npos) {
149 action_remote_prog(std::string_view(line).substr(1),
153 action_remote_prog(std::string_view(&line[1], space - 1),
154 std::string_view(line).substr(space + 1));
157 std::string::size_type colon = line.rfind(
':');
158 if (colon != std::string::npos) {
164 if (!(line[0] ==
'[' && line.back() ==
']')) {
167 std::string_view host{line};
168 host = host.substr(0, colon);
169 if (host[0] ==
'[' && host.back() ==
']') {
170 host = host.substr(1, host.size() - 2);
172 action_remote_tcp(host, port);
178 (void)action_remote_prog;
179 (void)action_remote_tcp;
184 if (type ==
"inmemory" && line.empty()) {
185 #ifdef XAPIAN_HAS_INMEMORY_BACKEND
189 (void)action_inmemory;
194 if (type ==
"chert") {
195 auto msg =
"Chert backend no longer supported";
199 if (type ==
"flint") {
200 auto msg =
"Flint backend no longer supported";
209 std::string msg{file};
Indicates an attempt to access a database not present.
DatabaseOpeningError indicates failure to open a database.
Indicates an attempt to use a feature which is unavailable.
int test_if_single_file_db(int fd)
Probe if a file descriptor is a single-file database.
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.
void resolve_relative_path(string &path, string_view base)
Resolve path relative to base.
File and path manipulation routines.
string str(int value)
Convert int to std::string.
Parse signed and unsigned type from string and check for trailing characters.
bool parse_unsigned(const char *p, T &res)
include <sys/stat.h> with portability enhancements
<unistd.h>, but with compat.
Convert types to std::string.