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 PrKaL2cNmWDhagAAgWs5BA (envelope-from ) for ; Mon, 10 May 2021 12:39:35 +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 CHWKKmcNmWCiIgAAbx9fmQ (envelope-from ) for ; Mon, 10 May 2021 10:39:35 +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 19A721828F for ; Mon, 10 May 2021 12:39:35 +0200 (CEST) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id F412D2717B; Mon, 10 May 2021 06:39:25 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 657A02716D for ; Mon, 10 May 2021 06:39:23 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id 6E08F60016; Mon, 10 May 2021 06:39:21 -0400 (EDT) Received: (nullmailer pid 56569 invoked by uid 1000); Mon, 10 May 2021 10:39:20 -0000 From: David Bremner To: Jack Kamm , notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH] lib/open: restore default database path of $HOME/mail Date: Mon, 10 May 2021 07:39:18 -0300 Message-Id: <20210510103918.56511-1-david@tethera.net> X-Mailer: git-send-email 2.30.2 In-Reply-To: <87eeefdc8b.fsf@gmail.com> References: <87eeefdc8b.fsf@gmail.com> MIME-Version: 1.0 Message-ID-Hash: EOLPZ4ZQOSPLK5ATGRWEZLWNW3OVBSFM X-Message-ID-Hash: EOLPZ4ZQOSPLK5ATGRWEZLWNW3OVBSFM 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=1620643175; 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=G5iCNepSpmeu9cbkohNpDl0w8A0IexUj42Vrd6b5BH8=; b=N81XRUNsf+HGNb3nOumTOEPaj3OAT8X/Rn/s8pBWDWyUlTJFwUpLq7Un95cUP8dXD8wFig SjVyZ1xieY2QjfGWsKLY5RiseC+Cc6kfyAzs52wTsEBl4y36XKB+WHed+YUuhd2NJXCe26 YqLHqxSOPv8Hk1/U7yX2X5RzP/WnIYnMczr2h1EZxRklqZDv5IeHvmlqbVtvuOcccDhwY3 BY7K1rB8w3p/jGlXSBgZ1ajU1h5msEFas7t8qOkZvCwsx+QxQ9Qdej41tJb4cWES0saNml 1rMVv1jT0q5algIjo8pNE2jAgro2ipTSpB05gPsd4FMSVoqDMJWhALCgSJFJBQ== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1620643175; a=rsa-sha256; cv=none; b=NhfbBQNXHCgAc9SjnyeQxtjhpN1u20I62salj1GGl5nyZvWtHmWdvPpYnsj5ZgNhIXC0hS Zgmf1ot/rkq/7vOXsOrWjEI3nKxLPMvRSOsd2uZIfc7OyrJk3mVHdLAedLJpfT1BBafN1u 3gRbn0pTqHtiQg1+llVQh5xjZI5M4p2B8o0zaLFNSnxJ6pQ8mXYc8fwmGdxL8YjqnaH+7M /RTfAhqK1hJbExyG/koypm7k7V4tSGPZdyffkxq7nJvuFAWAJBgu/UYJhuEzD7UYVc1p5g 2i0F48xobbxtTfSrqTbvjywB1W9cs7bQBVBQPwh8a0B0bjomigUofla3HUeOzw== 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: -0.05 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: 19A721828F X-Spam-Score: -0.05 X-Migadu-Scanner: scn0.migadu.com X-TUID: ZzPbII+PItHO Although this default worked for "notmuch config get", it didn't work most other places. Restore the previous functionality, with the wrinkle that XDG locations will shadow $HOME/mail if they exist. This fixes a bug reported by Jack Kamm in id:87eeefdc8b.fsf@gmail.com --- lib/open.cc | 19 ++++++++++++++++++- test/T055-path-config.sh | 22 ++++++++++++++++++++-- test/T560-lib-error.sh | 4 ++-- test/T590-libconfig.sh | 4 ++-- 4 files changed, 42 insertions(+), 7 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index bdb695fe..d7d2bedb 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -209,8 +209,25 @@ _choose_database_path (void *ctx, } } if (! *database_path) { + notmuch_status_t status; + *database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile); - *split = true; + status = _db_dir_exists (*database_path, message); + if (status) { + *database_path = NULL; + } else { + *split = true; + } + } + + if (! *database_path) { + notmuch_status_t status; + + *database_path = talloc_asprintf (ctx, "%s/mail", getenv ("HOME")); + status = _db_dir_exists (*database_path, message); + if (status) { + *database_path = NULL; + } } if (*database_path == NULL) { diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh index 2045a555..8ef76aed 100755 --- a/test/T055-path-config.sh +++ b/test/T055-path-config.sh @@ -16,6 +16,7 @@ restore_config () { unset DATABASE_PATH unset NOTMUCH_PROFILE unset XAPIAN_PATH + rm -f "$HOME/mail" cp notmuch-config-backup.${test_name} ${NOTMUCH_CONFIG} } @@ -42,6 +43,18 @@ symlink_config () { unset DATABASE_PATH } + +home_mail_config () { + local dir + backup_config + dir="${HOME}/mail" + ln -s $MAIL_DIR $dir + notmuch config set database.path + notmuch config set database.mail_root + XAPIAN_PATH="$MAIL_DIR/.notmuch/xapian" + unset DATABASE_PATH +} + xdg_config () { local dir local profile=${1:-default} @@ -66,7 +79,7 @@ xdg_config () { notmuch --config=${CONFIG_PATH} config set database.path } -for config in traditional split XDG XDG+profile symlink; do +for config in traditional split XDG XDG+profile symlink home_mail; do #start each set of tests with an known set of messages add_email_corpus @@ -90,6 +103,9 @@ for config in traditional split XDG XDG+profile symlink; do symlink) symlink_config ;; + home_mail) + home_mail_config + ;; esac test_begin_subtest "count ($config)" @@ -236,7 +252,9 @@ EOF test_begin_subtest "Config list ($config)" notmuch config list | notmuch_dir_sanitize | sed -e "s/^database.backup_dir=.*$/database.backup_dir/" \ -e "s/^database.hook_dir=.*$/database.hook_dir/" \ - -e "s/^database.path=.*$/database.path/" > OUTPUT + -e "s/^database.path=.*$/database.path/" \ + -e "s,^database.mail_root=CWD/home/mail,database.mail_root=MAIL_DIR," \ + > OUTPUT cat < EXPECTED built_with.compact=true built_with.field_processor=true diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh index 89447e9a..1f4482cb 100755 --- a/test/T560-lib-error.sh +++ b/test/T560-lib-error.sh @@ -22,7 +22,7 @@ EOF cat <<'EOF' >EXPECTED == stdout == == stderr == -Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory. +Error: could not locate database. EOF test_expect_equal_file EXPECTED OUTPUT @@ -93,7 +93,7 @@ EOF cat <<'EOF' >EXPECTED == stdout == == stderr == -Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory. +Error: could not locate database. EOF test_expect_equal_file EXPECTED OUTPUT diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index 51dd29c8..745e1bb4 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -546,8 +546,8 @@ cat <<'EOF' >EXPECTED == stdout == == stderr == error opening database -Something went wrong trying to read or write a file -Error: Cannot open database at CWD/home/.local/share/notmuch/default: No such file or directory. +No database found +Error: could not locate database. EOF test_expect_equal_file EXPECTED OUTPUT -- 2.30.2