]> git.notmuchmail.org Git - notmuch/commitdiff
lib/open: use notmuch->params to track split status
authorDavid Bremner <david@tethera.net>
Sat, 25 Dec 2021 13:33:03 +0000 (09:33 -0400)
committerDavid Bremner <david@tethera.net>
Sat, 15 Jan 2022 19:53:31 +0000 (15:53 -0400)
Persisting this status will allow us to use the information in other
compilation units, in particular when setting configuration defaults.

lib/database-private.h
lib/open.cc

index 8133e36415d85a58b381ef999791c2961caa54df..5db8882f0ba967a92787d5f75a2d2d2ef56b966d 100644 (file)
@@ -191,12 +191,17 @@ operator& (notmuch_field_flag_t a, notmuch_field_flag_t b)
                                    Xapian::QueryParser::FLAG_PURE_NOT)
 
 /*
- * Which parameters were explicit when the database was opened */
+ * explicit and implied parameters to open */
 typedef enum {
     NOTMUCH_PARAM_NONE         = 0,
+    /* database passed explicitely */
     NOTMUCH_PARAM_DATABASE     = 1 << 0,
+    /* config file passed explicitely */
     NOTMUCH_PARAM_CONFIG       = 1 << 1,
+    /* profile name passed explicitely */
     NOTMUCH_PARAM_PROFILE      = 1 << 2,
+    /* split (e.g. XDG) configuration */
+    NOTMUCH_PARAM_SPLIT                = 1 << 3,
 } notmuch_open_param_t;
 
 /*
index 4e5d25451aa7a6bb31b190556fe1de9cdcc2043f..30cfcf9e6a985728cc4c21024aed70eb72c1cf38 100644 (file)
@@ -190,7 +190,6 @@ _choose_database_path (notmuch_database_t *notmuch,
                       const char *profile,
                       GKeyFile *key_file,
                       const char **database_path,
-                      bool *split,
                       char **message)
 {
     if (! *database_path) {
@@ -215,7 +214,7 @@ _choose_database_path (notmuch_database_t *notmuch,
        if (status) {
            *database_path = NULL;
        } else {
-           *split = true;
+           notmuch->params |= NOTMUCH_PARAM_SPLIT;
        }
     }
 
@@ -513,7 +512,6 @@ notmuch_database_open_with_config (const char *database_path,
     notmuch_database_t *notmuch = NULL;
     char *message = NULL;
     GKeyFile *key_file = NULL;
-    bool split = false;
 
     _notmuch_init ();
 
@@ -530,7 +528,7 @@ notmuch_database_open_with_config (const char *database_path,
     }
 
     if ((status = _choose_database_path (notmuch, profile, key_file,
-                                        &database_path, &split,
+                                        &database_path,
                                         &message)))
        goto DONE;
 
@@ -610,7 +608,6 @@ notmuch_database_create_with_config (const char *database_path,
     char *message = NULL;
     GKeyFile *key_file = NULL;
     int err;
-    bool split = false;
 
     _notmuch_init ();
 
@@ -627,7 +624,7 @@ notmuch_database_create_with_config (const char *database_path,
     }
 
     if ((status = _choose_database_path (notmuch, profile, key_file,
-                                        &database_path, &split, &message)))
+                                        &database_path, &message)))
        goto DONE;
 
     status = _db_dir_exists (database_path, &message);
@@ -636,18 +633,19 @@ notmuch_database_create_with_config (const char *database_path,
 
     _set_database_path (notmuch, database_path);
 
-    if (key_file && ! split) {
+    if (key_file && ! (notmuch->params & NOTMUCH_PARAM_SPLIT)) {
        char *mail_root = notmuch_canonicalize_file_name (
            g_key_file_get_string (key_file, "database", "mail_root", NULL));
        char *db_path = notmuch_canonicalize_file_name (database_path);
 
-       split = (mail_root && (0 != strcmp (mail_root, db_path)));
+       if (mail_root && (0 != strcmp (mail_root, db_path)))
+           notmuch->params |= NOTMUCH_PARAM_SPLIT;
 
        free (mail_root);
        free (db_path);
     }
 
-    if (split) {
+    if (notmuch->params & NOTMUCH_PARAM_SPLIT) {
        notmuch_path = database_path;
     } else {
        if (! (notmuch_path = talloc_asprintf (notmuch, "%s/%s", database_path, ".notmuch"))) {
@@ -805,7 +803,6 @@ notmuch_database_load_config (const char *database_path,
     notmuch_database_t *notmuch = NULL;
     char *message = NULL;
     GKeyFile *key_file = NULL;
-    bool split = false;
 
     _notmuch_init ();
 
@@ -828,7 +825,7 @@ notmuch_database_load_config (const char *database_path,
     }
 
     status = _choose_database_path (notmuch, profile, key_file,
-                                   &database_path, &split, &message);
+                                   &database_path, &message);
     switch (status) {
     case NOTMUCH_STATUS_NO_DATABASE:
     case NOTMUCH_STATUS_SUCCESS: