From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 2I9sKxWJIGAMCwAA0tVLHw (envelope-from ) for ; Mon, 08 Feb 2021 00:43:01 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id 2KssJxWJIGDGawAAbx9fmQ (envelope-from ) for ; Mon, 08 Feb 2021 00:43:01 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [144.217.243.247]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4E5CD940481 for ; Mon, 8 Feb 2021 00:43:01 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id E459926A29; Sun, 7 Feb 2021 19:41:57 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 2D8F21FF16 for ; Sun, 7 Feb 2021 19:41:34 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 15B0D606DB; Sun, 7 Feb 2021 19:41:33 -0500 (EST) Received: (nullmailer pid 1193286 invoked by uid 1000); Mon, 08 Feb 2021 00:41:15 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 17/23] lib: remove "path" from notmuch struct Date: Sun, 7 Feb 2021 20:41:03 -0400 Message-Id: <20210208004109.1192719-18-david@tethera.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210208004109.1192719-1-david@tethera.net> References: <20210208004109.1192719-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: AOVCHIIJAHTFBLPQCB7VKND6PMSV4YW2 X-Message-ID-Hash: AOVCHIIJAHTFBLPQCB7VKND6PMSV4YW2 X-MailFrom: bremner@tethera.net X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; header-match-notmuch.notmuchmail.org-0; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; suspicious-header X-Mailman-Version: 3.2.1 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Post: List-Subscribe: List-Unsubscribe: Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -1.05 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 144.217.243.247 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 4E5CD940481 X-Spam-Score: -1.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: K65MLp5fyxNb 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