]> git.cworth.org Git - notmuch/commitdiff
lib/config: don't overwrite database.path if the caller passed it
authorDavid Bremner <david@tethera.net>
Thu, 28 Oct 2021 01:34:19 +0000 (22:34 -0300)
committerDavid Bremner <david@tethera.net>
Sat, 4 Dec 2021 00:52:11 +0000 (20:52 -0400)
If the user passed a path, and we opened it, then we consider that
definitive definition of "database.path". This makes libnotmuch
respond more gracefully to certain erroneous combinations of
NOTMUCH_CONFIG settings and config file contents.

lib/config.cc
test/T590-libconfig.sh

index 8775b00af8396280792e4af7049973b873f35586..e502858d623db091628e4945d7736c0db2d5b2cd 100644 (file)
@@ -259,7 +259,15 @@ _notmuch_config_load_from_database (notmuch_database_t *notmuch)
 
     for (; notmuch_config_list_valid (list); notmuch_config_list_move_to_next (list)) {
        const char *key = notmuch_config_list_key (list);
-       char *normalized_val = _expand_path (list, key, notmuch_config_list_value (list));
+       char *normalized_val = NULL;
+
+       /* If we opened from a given path, do not overwrite it */
+       if (strcmp (key, "database.path") == 0 &&
+           (notmuch->params & NOTMUCH_PARAM_DATABASE) &&
+           notmuch->xapian_db)
+           continue;
+
+       normalized_val = _expand_path (list, key, notmuch_config_list_value (list));
        _notmuch_string_map_append (notmuch->config, key, normalized_val);
        talloc_free (normalized_val);
     }
@@ -432,6 +440,13 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch,
                status = NOTMUCH_STATUS_FILE_ERROR;
                goto DONE;
            }
+
+           /* If we opened from a given path, do not overwrite it */
+           if (strcmp (absolute_key, "database.path") == 0 &&
+               (notmuch->params & NOTMUCH_PARAM_DATABASE) &&
+               notmuch->xapian_db)
+               continue;
+
            normalized_val = _expand_path (notmuch, absolute_key, val);
            _notmuch_string_map_set (notmuch->config, absolute_key, normalized_val);
            g_free (val);
index 0b3e54f3e86d144637290fadceaf11bf929d61ef..9fa51fc010c4da643194f4079e5015678b6b783c 100755 (executable)
@@ -953,7 +953,6 @@ EOF
 test_expect_equal_file EXPECTED OUTPUT
 
 test_begin_subtest "open: database parameter overrides implicit config"
-test_subtest_known_broken
 notmuch config set database.path ${MAIL_DIR}/nonexistent
 cat c_head3 - c_tail3 <<'EOF' | test_C ${MAIL_DIR}
   const char *path = NULL;