aboutsummaryrefslogtreecommitdiff
path: root/lib/open.cc
diff options
context:
space:
mode:
authorDavid Bremner <david@tethera.net>2020-08-08 11:16:36 -0300
committerDavid Bremner <david@tethera.net>2021-02-06 18:57:35 -0400
commite5f3c3ed50247323ecbd2a50e3b24a8352d17f8d (patch)
tree86adf8b40c3c3ca36755ddfe4213a8597dc35dc7 /lib/open.cc
parent4743e87c2c79c37208bb60d6617ef203796fc5c2 (diff)
lib: add stub for notmuch_database_open_with_config
Initially document the intended API and copy the code from notmuch_database_open_verbose. Most of the documented functionality is not there yet.
Diffstat (limited to 'lib/open.cc')
-rw-r--r--lib/open.cc42
1 files changed, 37 insertions, 5 deletions
diff --git a/lib/open.cc b/lib/open.cc
index 0001794a..7acaea7b 100644
--- a/lib/open.cc
+++ b/lib/open.cc
@@ -33,29 +33,56 @@ notmuch_database_open_verbose (const char *path,
notmuch_database_t **database,
char **status_string)
{
+ return notmuch_database_open_with_config (path, mode, "", NULL,
+ database, status_string);
+}
+
+notmuch_status_t
+notmuch_database_open_with_config (const char *database_path,
+ notmuch_database_mode_t mode,
+ const char *config_path,
+ unused(const char *profile),
+ notmuch_database_t **database,
+ char **status_string)
+{
notmuch_status_t status = NOTMUCH_STATUS_SUCCESS;
void *local = talloc_new (NULL);
notmuch_database_t *notmuch = NULL;
char *notmuch_path, *xapian_path, *incompat_features;
+ char *configured_database_path = NULL;
char *message = NULL;
struct stat st;
int err;
unsigned int version;
+ GKeyFile *key_file = NULL;
static int initialized = 0;
- if (path == NULL) {
+ /* XXX TODO: default locations for NULL case, handle profiles */
+ if (config_path != NULL && ! EMPTY_STRING (config_path)) {
+ key_file = g_key_file_new ();
+ if (! g_key_file_load_from_file (key_file, config_path, G_KEY_FILE_NONE, NULL)) {
+ status = NOTMUCH_STATUS_FILE_ERROR;
+ goto DONE;
+ }
+ configured_database_path = g_key_file_get_value (key_file, "database", "path", NULL);
+ }
+
+ if (database_path == NULL)
+ database_path = configured_database_path;
+
+ if (database_path == NULL) {
message = strdup ("Error: Cannot open a database for a NULL path.\n");
status = NOTMUCH_STATUS_NULL_POINTER;
goto DONE;
}
- if (path[0] != '/') {
+ if (database_path[0] != '/') {
message = strdup ("Error: Database path must be absolute.\n");
status = NOTMUCH_STATUS_PATH_ERROR;
goto DONE;
}
- if (! (notmuch_path = talloc_asprintf (local, "%s/%s", path, ".notmuch"))) {
+ if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
message = strdup ("Out of memory\n");
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;
@@ -89,8 +116,8 @@ notmuch_database_open_verbose (const char *path,
notmuch = talloc_zero (NULL, notmuch_database_t);
notmuch->exception_reported = false;
notmuch->status_string = NULL;
- notmuch->path = talloc_strdup (notmuch, path);
- notmuch->config = NULL;
+ notmuch->path = talloc_strdup (notmuch, database_path);
+
strip_trailing (notmuch->path, '/');
notmuch->writable_xapian_db = NULL;
@@ -185,6 +212,11 @@ notmuch_database_open_verbose (const char *path,
if (status)
goto DONE;
+ if (key_file)
+ status = _notmuch_config_load_from_file (notmuch, key_file);
+ if (status)
+ goto DONE;
+
status = _notmuch_database_setup_standard_query_fields (notmuch);
if (status)
goto DONE;