From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 8FktKTL+eWFEBQAAgWs5BA (envelope-from ) for ; Thu, 28 Oct 2021 03:34:42 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id gBfkJDL+eWE3KAAAbx9fmQ (envelope-from ) for ; Thu, 28 Oct 2021 01:34:42 +0000 Received: from mail.notmuchmail.org (nmbug.tethera.net [IPv6:2607:5300:201:3100::1657]) (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 E81D522CB9 for ; Thu, 28 Oct 2021 03:34:41 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 712391F858; Wed, 27 Oct 2021 21:34:33 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 75CED1F73C for ; Wed, 27 Oct 2021 21:34:27 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 6E6AE5FC42; Wed, 27 Oct 2021 21:34:27 -0400 (EDT) Received: (nullmailer pid 3999838 invoked by uid 1000); Thu, 28 Oct 2021 01:34:25 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 3/3] lib/config: don't overwrite database.path if the caller passed it Date: Wed, 27 Oct 2021 22:34:19 -0300 Message-Id: <20211028013419.3996019-4-david@tethera.net> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211028013419.3996019-1-david@tethera.net> References: <20211028013419.3996019-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: CYTM3EGPPHRN5TZ355XT2B3CQK4UBVKH X-Message-ID-Hash: CYTM3EGPPHRN5TZ355XT2B3CQK4UBVKH 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; digests; suspicious-header X-Mailman-Version: 3.3.3 Precedence: list List-Id: "Use and development of the notmuch mail system." List-Help: List-Owner: 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=1635384882; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to: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-owner:list-unsubscribe:list-subscribe:list-post; bh=IcCiJg8MKdUfLx2PspKOIEhXHgktmmW9ht1THz5z4So=; b=flEEwyR2V0ot4pq8QiT+SlizFzAPLybAn/okW9bsaYr1ZB7eqmZd7txphtkY00zsmrZQFS 9NfHMI0UnaCEwEvbKscog9GKL77YGsJV3Yp/3OGN9pic9espvrj5PEnef5Q9oaTHlDimBa VjUYBdUeaalq+Ll9N46vziM7Hoy9WljcUBtTgXaIzDaNXYFSm8OQ+3TvINHsVm4VoH2KcT BSDEeO5IH0pSgjWIYOmiRTdQrE8VhSpTPnute+2BgA9Cv9zvN24UpDvoO8lJFcbG+BVnRo DeoifsY5bet3rTSaYlnMP9xZoX/VDeJT8jEmDyG7x7NgWaDH6Nz46YBwBW/mNg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1635384882; a=rsa-sha256; cv=none; b=WGJ9rQYNiGZQOrf5JpMUGzKRDScrFMoYxUZFDtvXQYZeBUrZzsdYKSDPcXraPAW6onBHMI UhAdKFsFs4VqqXu/RBQSqu6npV7msLDJsQK+wtCIdcOXGePxHW3rnrjIkLlnicgiekOw9U 5dCmsdtYvLBS9F1nDc2U3qVxFUoS0QLa307EDqzGF/e1f+WRl2Qt+X2odLMmiPpH3amGEz z4loRfCFXkMOb8EVBtj8xiDIsCTtOhzu5okuxk4qby5zZo/cS7eS7DMzkQGXgGIbFEjoW9 j1rwx2R0UWrS7rJTxr4Y3Jr0/tGHNXk5umg3iu7a8Rak84enj7mobOrnxh62cA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.14 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 2607:5300:201:3100::1657 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: E81D522CB9 X-Spam-Score: -1.14 X-Migadu-Scanner: scn0.migadu.com X-TUID: foY4pAqn3d3B 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 | 17 ++++++++++++++++- 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 eab70ae9..30bdb1b0 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; -- 2.33.0