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 2F0LBeIXTmAQHgAA0tVLHw (envelope-from ) for ; Sun, 14 Mar 2021 14:04:18 +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 AKnJAOIXTmAvRAAAB5/wlQ (envelope-from ) for ; Sun, 14 Mar 2021 14:04:18 +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)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 3D41112BA7 for ; Sun, 14 Mar 2021 15:04:17 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id B9A0E28C5A; Sun, 14 Mar 2021 10:02:59 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id C353827C5A for ; Sun, 14 Mar 2021 10:02:36 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id BAE095FA96; Sun, 14 Mar 2021 10:02:36 -0400 (EDT) Received: (nullmailer pid 183642 invoked by uid 1000); Sun, 14 Mar 2021 14:02:19 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 06/22] lib/open: support NOTMUCH_DATABASE environment variable Date: Sun, 14 Mar 2021 11:02:01 -0300 Message-Id: <20210314140217.183425-7-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: GHDXITZS3T32YSY4WQ3WSFK66DNPTXBD X-Message-ID-Hash: GHDXITZS3T32YSY4WQ3WSFK66DNPTXBD 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=1615730657; 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=fTuTQwXQ0Rd9JKhfZszITQpu/I0qINk+gwRQXVs4PbY=; b=LifjP4UBo5dj94px68ZP7KToytFg8iwc0POCIJ/7U3R2ciryecSrRE6qxbeJ2DaYD2O/qv fYgfk3yqr1UhH+FxnhUfrmmYKeZAqTyuFGsdp8IGq97xvyBNBf0NEvHqSeyDWtu3AcfJbG Wk6dDID52E4yOrrEcQtP2PMXEq2lk34NBbx8AY3MrpdVsKzfMb+l0kq4f/PCWJ5tDOoT3M 0a5YRshQnJMzm2GaRsKLSPfy0rwjvXveeYcrXRNAZ5M7+blEFiTvf9nRF1EvEe8lPD4Hd5 D3I3gq9t0/OQoYwMyi6DWXB3PpcmpD+IrdgKX87p6G/5VQuG1YazLqOdWNYt2w== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615730657; a=rsa-sha256; cv=none; b=bacsMjr9vuHrBqvfZ6OZAR/GDfRRZPO0lShopWxv3T3XDpDbLYanM8mTDXXnm8iM1T8xzJ lgRJoeZFp2BhdH4zATTBx39bVyhonIVH64KMJMewRmqD0li1KIvpkrwPSBFZcfpw/7YD0C G2v9Tq3Q38pfitIxEI8XaksGSTPjREhVW0fB9aDXqw4FnQb29hebMq+1ogGMf8ZuTvCDN9 IVoL4fFrBYnw79CunLRpU7lMcUcN1GkSTTWzwkXE9FBC6q0VGjeUr8N47nEAw4DuEDvV00 u1m69zIvZlxR+o/V6LaMXIu518XVVw+vQynpAM5E7h04chR3HeUHnpBsCJwqlQ== 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: 3D41112BA7 X-Spam-Score: -1.09 X-Migadu-Scanner: scn0.migadu.com X-TUID: uLxfajia6RNL 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 d05a19a7..6e46168a 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -168,6 +168,10 @@ _choose_database_path (void *ctx, return status; } + if (! *database_path) { + *database_path = getenv ("NOTMUCH_DATABASE"); + } + if (! *database_path && *key_file) { char *path = g_key_file_get_value (*key_file, "database", "path", NULL); if (path) { diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index e7e6e08a..4e510e97 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 @@ -505,4 +505,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.30.1