From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 4DpiGQwllWC1NgEAgWs5BA (envelope-from ) for ; Fri, 07 May 2021 13:31:24 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id cEwLFQwllWAXYgAAB5/wlQ (envelope-from ) for ; Fri, 07 May 2021 11:31:24 +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 0B67219ACA for ; Fri, 7 May 2021 13:31:24 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 3B23327DFC; Fri, 7 May 2021 07:31:06 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 4ADD127167 for ; Fri, 7 May 2021 07:30:59 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 42D5E60016; Fri, 7 May 2021 07:30:59 -0400 (EDT) Received: (nullmailer pid 2687415 invoked by uid 1000); Fri, 07 May 2021 11:30:57 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 2/9] lib/config: canonicalize paths relative to $HOME. Date: Fri, 7 May 2021 08:30:22 -0300 Message-Id: <20210507113029.2685184-3-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210507113029.2685184-1-david@tethera.net> References: <20210507113029.2685184-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: KKIFESKNVF2LBVNCR7N3BTBH3SMJWEV6 X-Message-ID-Hash: KKIFESKNVF2LBVNCR7N3BTBH3SMJWEV6 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=1620387084; 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=kuQxMi/wTESzGn9Tzw+93atGvUstk0uuTnlI2JvEQyo=; b=u1jI7g71lpJvB3GjSSyb2CGVKC3F3lFVE9Lh77/1DMA44D9TOrpTotoR8qGLkdJ9ifC4od 1qOsCfSttjXCrF+vsTdqA88PzwfpqwWub8+Pxct+kw1iP5crsmvQ0sKY5lUFUlZEClzJNu PKEuyqtMY4WAGdp9QfY3QtjDA1xGvewK2u1OF7qk1c540qgyrqZJUlUwEiAxnIM5UffLaO +NJ3qPUX8hfss7F+dpDrVbtFwlnW5Z6jfsfzC7JnpsF7a8dodhJWuTxPPqo5gp2VaNZn9p UJht67+QZeAz8SCCOFlj2C8fpwARb24Ll7B5VoDmnsqth/i20Ixy2TpjoZf1OA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1620387084; a=rsa-sha256; cv=none; b=gAlVac8svUx9BKV4poDX58Yjdhc7v9/2vvjFZ9MmVyKYoCZAB+UzyBf68YUxKb8W0VWkri Q4THqHSnO93yPnHNyZJutKc1Ks1+PicWSYjxz0pvmLa1GdyQBy8qzNM+9VYjifiqZix/Oi tp/arRc8Ze1nhGgNXShgTkY55ifllD/Hm4EGYwQNeoUKgvEq6q5MEpOJPMefUyc9F/9hOh cBhrMmv5fY9MBuFsCorcWLFrP9vUU+a2kPSR5Q5ovNC2MVf6DJ469oRWvCzPmG668LQs06 zC0oMw3B8F4MEyqSAGSamBWYINRYKnfSAKN29ieKRjMbH7/JuVDyeFmIwXlebw== 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.44 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: 0B67219ACA X-Spam-Score: 1.44 X-Migadu-Scanner: scn0.migadu.com X-TUID: G7ZTnEPe6hLn Prior to 0.32, notmuch had the (undocumented) behaviour that it expanded a relative value of database.path with respect to $HOME. In 0.32 this was special cased for database.path but broken for database.mail_root, which causes problems for at least notmuch-new when database.path is set to a relative path. The change in T030-config.sh reflects a user visible, but hopefully harmless behaviour change; the expanded form of the paths will now be printed by notmuch config. --- lib/config.cc | 22 +++++++++++++++++++++- test/T030-config.sh | 6 +++--- test/T050-new.sh | 1 - 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/config.cc b/lib/config.cc index 50bcf6a2..e08c6bf7 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -387,6 +387,23 @@ notmuch_config_pairs_destroy (notmuch_config_pairs_t *pairs) talloc_free (pairs); } +static char * +_expand_path (void *ctx, const char *key, const char *val) +{ + char *expanded_val; + + if ((strcmp (key, "database.path") == 0 || + strcmp (key, "database.mail_root") == 0 || + strcmp (key, "database.hook_dir") == 0 || + strcmp (key, "database.backup_path") == 0 ) && + val[0] != '/') + expanded_val = talloc_asprintf (ctx, "%s/%s", getenv("HOME"), val); + else + expanded_val = talloc_strdup (ctx, val); + + return expanded_val; +} + notmuch_status_t _notmuch_config_load_from_file (notmuch_database_t *notmuch, GKeyFile *file) @@ -407,14 +424,17 @@ _notmuch_config_load_from_file (notmuch_database_t *notmuch, keys = g_key_file_get_keys (file, *grp, NULL, NULL); for (gchar **keys_p = keys; *keys_p; keys_p++) { char *absolute_key = talloc_asprintf (notmuch, "%s.%s", *grp, *keys_p); + char *normalized_val; val = g_key_file_get_value (file, *grp, *keys_p, NULL); if (! val) { status = NOTMUCH_STATUS_FILE_ERROR; goto DONE; } - _notmuch_string_map_set (notmuch->config, absolute_key, val); + normalized_val = _expand_path (notmuch, absolute_key, val); + _notmuch_string_map_set (notmuch->config, absolute_key, normalized_val); g_free (val); talloc_free (absolute_key); + talloc_free (normalized_val); if (status) goto DONE; } diff --git a/test/T030-config.sh b/test/T030-config.sh index b22d8f29..7a1660e9 100755 --- a/test/T030-config.sh +++ b/test/T030-config.sh @@ -117,12 +117,12 @@ test_expect_equal "$(notmuch config get database.path)" \ ln -s `pwd`/mail home/Maildir add_email_corpus -test_begin_subtest "Relative database path expanded in open" +test_begin_subtest "Relative database path expanded" notmuch config set database.path Maildir -path=$(notmuch config get database.path) +path=$(notmuch config get database.path | notmuch_dir_sanitize) count=$(notmuch count '*') test_expect_equal "${path} ${count}" \ - "Maildir 52" + "CWD/home/Maildir 52" test_begin_subtest "Add config to database" notmuch new diff --git a/test/T050-new.sh b/test/T050-new.sh index 5faf6839..33ad7f5a 100755 --- a/test/T050-new.sh +++ b/test/T050-new.sh @@ -395,7 +395,6 @@ EOF test_expect_equal_file EXPECTED OUTPUT test_begin_subtest "Relative database path expanded in new" -test_subtest_known_broken ln -s `pwd`/mail home/Maildir notmuch config set database.path Maildir generate_message -- 2.30.2