[PATCH 06/19] WIP: initial retrieval of database path from config file

Subject: [PATCH 06/19] WIP: initial retrieval of database path from config file

Date: Sat, 8 Aug 2020 11:16:40 -0300

To: notmuch@notmuchmail.org

Cc: David Bremner

From: David Bremner


---
 lib/database.cc | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/lib/database.cc b/lib/database.cc
index 350abb11..2ab9170d 100644
--- a/lib/database.cc
+++ b/lib/database.cc
@@ -935,12 +935,27 @@ notmuch_database_open_with_config (const char *database_path,
     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 i, version;
+    GKeyFile *key_file = NULL;
     static int initialized = 0;
 
+    /* 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;
@@ -1100,6 +1115,9 @@ notmuch_database_open_with_config (const char *database_path,
   DONE:
     talloc_free (local);
 
+    if (key_file)
+	g_key_file_free (key_file);
+
     if (message) {
 	if (status_string)
 	    *status_string = message;
-- 
2.28.0
_______________________________________________
notmuch mailing list -- notmuch@notmuchmail.org
To unsubscribe send an email to notmuch-leave@notmuchmail.org

Thread: