This removes duplication between the struct element and the configuration string_map entry. --- lib/config.cc | 3 +++ lib/database-private.h | 3 --- lib/database.cc | 2 +- lib/open.cc | 22 +++++++++++++++------- 4 files changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/config.cc b/lib/config.cc index bfa6b4ae..44d546db 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -478,5 +478,8 @@ notmuch_config_set (notmuch_database_t *notmuch, notmuch_config_key_t key, const void _notmuch_config_cache (notmuch_database_t *notmuch, notmuch_config_key_t key, const char *val) { + if (notmuch->config == NULL) + notmuch->config = _notmuch_string_map_create (notmuch); + _notmuch_string_map_set (notmuch->config, _notmuch_config_key_to_string (key), val); } diff --git a/lib/database-private.h b/lib/database-private.h index d936b216..2900382d 100644 --- a/lib/database-private.h +++ b/lib/database-private.h @@ -189,9 +189,6 @@ operator& (notmuch_field_flag_t a, notmuch_field_flag_t b) struct _notmuch_database { bool exception_reported; - /* Path to database parent directory and or/mail root */ - char *path; - /* Path to actual database */ const char *xapian_path; diff --git a/lib/database.cc b/lib/database.cc index 1fc3ce9c..1d8839a5 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -748,7 +748,7 @@ notmuch_database_destroy (notmuch_database_t *notmuch) const char * notmuch_database_get_path (notmuch_database_t *notmuch) { - return notmuch->path; + return notmuch_config_get (notmuch, NOTMUCH_CONFIG_DATABASE_PATH); } unsigned int diff --git a/lib/open.cc b/lib/open.cc index efb0d6a3..a577ddca 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -305,6 +305,7 @@ _finish_open (notmuch_database_t *notmuch, char *incompat_features; char *message = NULL; unsigned int version; + const char *database_path = notmuch_database_get_path (notmuch); try { std::string last_thread_id; @@ -327,7 +328,7 @@ _finish_open (notmuch_database_t *notmuch, "Error: Notmuch database at %s\n" " has a newer database format version (%u) than supported by this\n" " version of notmuch (%u).\n", - notmuch->path, version, NOTMUCH_DATABASE_VERSION)); + database_path, version, NOTMUCH_DATABASE_VERSION)); notmuch_database_destroy (notmuch); notmuch = NULL; status = NOTMUCH_STATUS_FILE_ERROR; @@ -345,7 +346,7 @@ _finish_open (notmuch_database_t *notmuch, "Error: Notmuch database at %s\n" " requires features (%s)\n" " not supported by this version of notmuch.\n", - notmuch->path, incompat_features)); + database_path, incompat_features)); notmuch_database_destroy (notmuch); notmuch = NULL; status = NOTMUCH_STATUS_FILE_ERROR; @@ -429,6 +430,16 @@ _finish_open (notmuch_database_t *notmuch, return status; } +static void +_set_database_path (notmuch_database_t *notmuch, + const char *database_path) { + char *path=talloc_strdup (notmuch, database_path); + + strip_trailing (path, '/'); + + _notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path); +} + notmuch_status_t notmuch_database_open_with_config (const char *database_path, notmuch_database_mode_t mode, @@ -461,8 +472,7 @@ notmuch_database_open_with_config (const char *database_path, if (status) goto DONE; - notmuch->path = talloc_strdup (notmuch, database_path); - strip_trailing (notmuch->path, '/'); + _set_database_path (notmuch, database_path); status = _choose_xapian_path (local, database_path, ¬much->xapian_path, &message); if (status) @@ -547,8 +557,7 @@ notmuch_database_create_with_config (const char *database_path, if (status) goto DONE; - notmuch->path = talloc_strdup (notmuch, database_path); - strip_trailing (notmuch->path, '/'); + _set_database_path (notmuch, database_path); if (key_file && !split) { const char *mail_root = g_key_file_get_value (key_file, "database", "mail_root", NULL); @@ -565,7 +574,6 @@ notmuch_database_create_with_config (const char *database_path, } err = mkdir (notmuch_path, 0755); - if (err) { if (errno == EEXIST) { status = NOTMUCH_STATUS_DATABASE_EXISTS; -- 2.30.0 _______________________________________________ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-leave@notmuchmail.org