diff options
| author | David Bremner <david@tethera.net> | 2021-10-27 22:34:19 -0300 |
|---|---|---|
| committer | David Bremner <david@tethera.net> | 2021-12-03 20:52:11 -0400 |
| commit | 59aac9cef37a9937bdf2265078d063673111f80b (patch) | |
| tree | e375644b87d0c21d4f3afbefbcfab7b849c7572c | |
| parent | d467444085d96229172ce29ef8654c3c459b6ce2 (diff) | |
lib/config: don't overwrite database.path if the caller passed it
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.
| -rw-r--r-- | lib/config.cc | 17 | ||||
| -rwxr-xr-x | test/T590-libconfig.sh | 1 |
2 files changed, 16 insertions, 2 deletions
diff --git a/lib/config.cc b/lib/config.cc index 8775b00a..e502858d 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -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); diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index 0b3e54f3..9fa51fc0 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -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; |
