From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id 074xDZHS819FCAAA0tVLHw (envelope-from ) for ; Tue, 05 Jan 2021 02:44:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id sLd2CJHS81+1YAAAB5/wlQ (envelope-from ) for ; Tue, 05 Jan 2021 02:44:33 +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) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E528994021E for ; Tue, 5 Jan 2021 02:44:32 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id C613829CFA; Mon, 4 Jan 2021 21:44:15 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id BDBBE28535 for ; Mon, 4 Jan 2021 21:44:09 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id EABAF6066D; Mon, 4 Jan 2021 21:24:11 -0500 (EST) Received: (nullmailer pid 644499 invoked by uid 1000); Tue, 05 Jan 2021 02:24:06 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 1/5] lib/open: support NOTMUCH_DATABASE environment variable Date: Mon, 4 Jan 2021 22:23:46 -0400 Message-Id: <20210105022350.643917-2-david@tethera.net> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210105022350.643917-1-david@tethera.net> References: <20210105022350.643917-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 6DWTJ7EOFITCY6JZGKBQTROKW4OFYCSM X-Message-ID-Hash: 6DWTJ7EOFITCY6JZGKBQTROKW4OFYCSM 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: 0.61 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: E528994021E X-Spam-Score: 0.61 X-Migadu-Scanner: scn0.migadu.com X-TUID: iYJP11YsrpuT The additional code is trivial, but making sure we get the priority of various options correct takes a few tests. --- lib/open.cc | 4 +++ test/T590-libconfig.sh | 67 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 70 insertions(+), 1 deletion(-) diff --git a/lib/open.cc b/lib/open.cc index 92661271..acc9f7a4 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -162,6 +162,10 @@ notmuch_database_open_with_config (const char *database_path, GKeyFile *key_file = NULL; static int initialized = 0; + if (! database_path) { + database_path = getenv ("NOTMUCH_DATABASE"); + } + if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message))) goto DONE; diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index 97f8fdc7..7f187d36 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -27,7 +27,7 @@ int main (int argc, char** argv) &db, &msg); if (stat != NOTMUCH_STATUS_SUCCESS) { - fprintf (stderr, "error opening database: %d %s\n", stat, msg ? msg : ""); + fprintf (stderr, "error opening database\n%s\n%s\n", notmuch_status_to_string (stat), msg ? msg : ""); exit (1); } EOF @@ -473,4 +473,69 @@ EOF test_expect_equal_file EXPECTED OUTPUT restore_database +test_begin_subtest "no config, fail to open database" +old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG} +unset NOTMUCH_CONFIG +cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL% +{ + printf("NOT RUN"); +} +EOF +NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} +cat <<'EOF' >EXPECTED +== stdout == +== stderr == +error opening database +Erroneous NULL pointer +Error: Cannot open a database for a NULL path. + +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "open database from NOTMUCH_DATABASE" +old_NOTMUCH_CONFIG=${NOTMUCH_CONFIG} +unset NOTMUCH_CONFIG +export NOTMUCH_DATABASE=${MAIL_DIR} +cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL% +{ + EXPECT0(notmuch_database_get_config (db, "test.key1", &val)); + printf("test.key1 = %s\n", val); + EXPECT0(notmuch_database_get_config (db, "test.key2", &val)); + printf("test.key2 = %s\n", val); +} +EOF +NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} +unset NOTMUCH_DATABASE +cat <<'EOF' >EXPECTED +== stdout == +test.key1 = testvalue1 +test.key2 = testvalue2 +== stderr == +EOF +test_expect_equal_file EXPECTED OUTPUT + +test_begin_subtest "NOTMUCH_DATABASE overrides config" +old_path=$(notmuch config get database.path) +notmuch config set database.path /nonexistent +export NOTMUCH_DATABASE=${MAIL_DIR} +cat c_head - c_tail <<'EOF' | test_C %NULL% '' %NULL% +{ + EXPECT0(notmuch_database_get_config (db, "test.key1", &val)); + printf("test.key1 = %s\n", val); + EXPECT0(notmuch_database_get_config (db, "test.key2", &val)); + printf("test.key2 = %s\n", val); +} +EOF +NOTMUCH_CONFIG=${old_NOTMUCH_CONFIG} +unset NOTMUCH_DATABASE +cat <<'EOF' >EXPECTED +== stdout == +test.key1 = testvalue1 +test.key2 = testvalue2 +== stderr == +EOF +notmuch config set database.path "${old_path}" +test_expect_equal_file EXPECTED OUTPUT + + test_done -- 2.29.2