From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id uObpHJAXTmAVFgAA0tVLHw (envelope-from ) for ; Sun, 14 Mar 2021 14:02:56 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id IO2OGJAXTmCkTgAAbx9fmQ (envelope-from ) for ; Sun, 14 Mar 2021 14:02:56 +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) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id D556E1CF63 for ; Sun, 14 Mar 2021 15:02:55 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 05AF727C38; Sun, 14 Mar 2021 10:02:33 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id E3A112705A for ; Sun, 14 Mar 2021 10:02:24 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id C59B95FA96; Sun, 14 Mar 2021 10:02:24 -0400 (EDT) Received: (nullmailer pid 183648 invoked by uid 1000); Sun, 14 Mar 2021 14:02:19 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 08/22] lib: remove "path" from notmuch struct Date: Sun, 14 Mar 2021 11:02:03 -0300 Message-Id: <20210314140217.183425-9-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210314140217.183425-1-david@tethera.net> References: <20210314140217.183425-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: JNUZ6EJF7RZSSJKPHXXH4SWDPZUMRVBQ X-Message-ID-Hash: JNUZ6EJF7RZSSJKPHXXH4SWDPZUMRVBQ 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 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1615730575; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=+lNSTz48n5ZxythH+R2gNUqVG6TE90os3cD/KAaMBQc=; b=ZjCRonAkLSt5yVpLG8pO+3SWR1dFpy9zibqQm2EhvhyNF4EFlzpg9MtjmNtgV8fugGUdzl A6YE3tmStPAYQpLeoi/o24jhFo76GoKq+0xVUf1ld7F4ZxNR9Kh+Diq6zgTZx3vyv5AvxV Xh2/ancrZBLHmmagT+Lp5JLnYba+i/AJhku7DbMeKI+TyGnyrS2nDmI0EZj1aQaUKbZ2of nyK3C5XPMc+YtHJ9BBAY5XQF+UzIbKqEHCTFmB0Bz+QotAgZYw6yI9/HjHPqGlRj9PZlZi cD048xZESkHuDU17Qg46d5DI6oX6cLUCXyED1stCxoOzduyZPS49/nUShGe/og== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615730575; a=rsa-sha256; cv=none; b=ONmiUluRw983NbTzcKN2mIbuTEObOdvFRC2lkREvuJeS6nXoo85xzJ6TJSqGc84+W6izi4 tlFO6DgVcRfrhZouq3dt+0BclQyy8uIxNAcCUgiJeR/BCkg7wt+FoglYd0zbR4wCG3Mg7w gFeHHJVa3ZiYBbckNjIEZL+8jxuJeKA9jONwt1Zw3F7HxbycoTJ5vakbKZfqprNORSBcEc gccJ/BYDxreeOdFBmiR1ksBJ99VJ19iWhC2G0hwS1rRqXFyKRCc1DLQjjA6xouy0Y4Uzn4 cMvODzuUUpbiecF5ke4IfQXX+Ee7EvrvdNNTDQzKeoVA9gipkcT0eLbFWd5cQw== ARC-Authentication-Results: i=1; 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-Spam-Score: -1.09 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: D556E1CF63 X-Spam-Score: -1.09 X-Migadu-Scanner: scn0.migadu.com X-TUID: 9YdEjS04gMjR This removes duplication between the struct element and the configuration string_map entry. Create a simple wrapper for setting the database path that makes sure the trailing / is stripped. --- lib/config.cc | 3 +++ lib/database-private.h | 3 --- lib/database.cc | 2 +- lib/open.cc | 14 ++++++++++++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/config.cc b/lib/config.cc index 6993e67f..483a02ef 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -496,5 +496,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 fc13b53b..580b2d58 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -752,7 +752,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 de5f3467..a62d4dee 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -209,6 +209,17 @@ _alloc_notmuch () return notmuch; } +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, @@ -238,8 +249,7 @@ notmuch_database_open_with_config (const char *database_path, &key_file, &database_path, &message))) goto DONE; - notmuch->path = talloc_strdup (notmuch, database_path); - strip_trailing (notmuch->path, '/'); + _set_database_path (notmuch, database_path); if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) { message = strdup ("Out of memory\n"); -- 2.30.1