From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp11.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id cC3YDI3Q42LIZwAAbAwnHQ (envelope-from ) for ; Fri, 29 Jul 2022 14:20:29 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp11.migadu.com with LMTPS id 8JTmDI3Q42LLgwAA9RJhRA (envelope-from ) for ; Fri, 29 Jul 2022 14:20:29 +0200 Received: from mail.notmuchmail.org (yantan.tethera.net [135.181.149.255]) (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 0BE3D2C936 for ; Fri, 29 Jul 2022 14:20:28 +0200 (CEST) Received: from yantan.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 007F85F37C; Fri, 29 Jul 2022 12:20:18 +0000 (UTC) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id E54515F36F for ; Fri, 29 Jul 2022 12:20:13 +0000 (UTC) Received: by fethera.tethera.net (Postfix, from userid 1001) id 20D0A5FBD7; Fri, 29 Jul 2022 08:20:13 -0400 (EDT) Received: (nullmailer pid 1557193 invoked by uid 1000); Fri, 29 Jul 2022 12:20:10 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: [PATCH 5/6] lib/open: return non-SUCCESS on missing database path Date: Fri, 29 Jul 2022 09:20:00 -0300 Message-Id: <20220729122001.1556787-6-david@tethera.net> X-Mailer: git-send-email 2.35.2 In-Reply-To: <20220729122001.1556787-1-david@tethera.net> References: <20220729122001.1556787-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: LYOE5BDOS5WIKTCOSV4JN66RTWYWFYK2 X-Message-ID-Hash: LYOE5BDOS5WIKTCOSV4JN66RTWYWFYK2 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 CC: spwhitton@spwhitton.name 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 X-Migadu-To: larch@yhetil.org X-Migadu-Country: DE ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659097229; 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-owner:list-unsubscribe:list-subscribe:list-post; bh=oqAqbgh2Wp6XT6mWY2t2WhaFln4XBY9whSFcqM62Nqw=; b=hMMCujg+xngjPlzMXY19RiFp+qFa03ZyGHJA24q9ZyNu/2KHxZoO5Rkpp9f6NNhPGF7SZS mEywRWRIeXuKHxySOID/jaTr12XTwpHbB2wtkSxd0REVOhDJBljz60vk9dEaEt/eJ7+C6k SZpMowLFGnc2nJyGsN0M8NLzqx+dMbHQOVDN6dHqM/lvT8oXmxMxyDFSAR9MOpL0zm29wG CHwvzDKrFO8XgRIFfCdVp/5oRJTbUI9J5s88m5z0xMBzF06S5Rx5aZVK0/rhNiR9qFvUhx c2+GyGdxSn4pkjvRxg/rxWf77PHcxIpw+vh49s+pWjd+1uW1keJgFkTTQd+J/Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659097229; a=rsa-sha256; cv=none; b=LMIUqjDapPLHKvZE8mv9mhyDnBgL1SMductgMc4KJzLL2tUJ6t5qpOJlO8i/4+hN3ZPtyk ubpBIief3sR+xonwZ3WUFP5oJs2OtobbJdY1lnHGHOYvuf/3yqAegZLfu5CQtQQpYkDXUy 0Ti9kEZBMte3AzMTvy3BDJKF4MO7PSD60Pnn5z2qu+L+67zLVpq1pIcrH790f6mIVsR2Pi 1NJQgxVAi3lPnaaIjRjG/MLktP2NFjKjp+yeYMycHGM/gdGeh+7cXRHJuBIWyD48tPJciO nvTjBU0fjDOCQZ5bT+urHL3K1kH4CRCT2I1yBgeCB+BLvkomsWZ8N/bVe5mOGg== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Spam-Score: -1.78 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of notmuch-bounces@notmuchmail.org designates 135.181.149.255 as permitted sender) smtp.mailfrom=notmuch-bounces@notmuchmail.org X-Migadu-Queue-Id: 0BE3D2C936 X-Spam-Score: -1.78 X-Migadu-Scanner: scn0.migadu.com X-TUID: 2Rr78FetrTSu This simplifies the logic of creating the directory path when it doesn't exist. --- lib/open.cc | 19 +++++++++++-------- test/T560-lib-error.sh | 4 ++-- 2 files changed, 13 insertions(+), 10 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 85e46dc7..bc450555 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -192,6 +192,8 @@ _choose_database_path (notmuch_database_t *notmuch, const char **database_path, char **message) { + notmuch_status_t status; + if (! *database_path) { *database_path = getenv ("NOTMUCH_DATABASE"); } @@ -207,8 +209,6 @@ _choose_database_path (notmuch_database_t *notmuch, } } if (! *database_path) { - notmuch_status_t status; - *database_path = _xdg_dir (notmuch, "XDG_DATA_HOME", ".local/share", profile); status = _db_dir_exists (*database_path, message); if (status) { @@ -223,8 +223,6 @@ _choose_database_path (notmuch_database_t *notmuch, } if (! *database_path) { - notmuch_status_t status; - *database_path = talloc_asprintf (notmuch, "%s/mail", getenv ("HOME")); status = _db_dir_exists (*database_path, message); if (status) { @@ -241,6 +239,15 @@ _choose_database_path (notmuch_database_t *notmuch, *message = strdup ("Error: Database path must be absolute.\n"); return NOTMUCH_STATUS_PATH_ERROR; } + + status = _db_dir_exists (*database_path, message); + if (status) { + IGNORE_RESULT (asprintf (message, + "Error: database path '%s' does not exist or is not a directory.\n", + *database_path)); + return NOTMUCH_STATUS_NO_DATABASE; + } + return NOTMUCH_STATUS_SUCCESS; } @@ -638,10 +645,6 @@ notmuch_database_create_with_config (const char *database_path, &database_path, &message))) goto DONE; - status = _db_dir_exists (database_path, &message); - if (status) - goto DONE; - _set_database_path (notmuch, database_path); if (key_file && ! (notmuch->params & NOTMUCH_PARAM_SPLIT)) { diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh index a2901ff6..30cce943 100755 --- a/test/T560-lib-error.sh +++ b/test/T560-lib-error.sh @@ -91,7 +91,7 @@ EOF cat <<'EOF' >EXPECTED == stdout == == stderr == -Error: Cannot open database at CWD/nonexistent/foo: No such file or directory. +Error: database path 'CWD/nonexistent/foo' does not exist or is not a directory. EOF test_expect_equal_file EXPECTED OUTPUT @@ -132,7 +132,7 @@ EOF cat <<'EOF' >EXPECTED == stdout == == stderr == -Error: Cannot open database at CWD/nonexistent/foo: No such file or directory. +Error: database path 'CWD/nonexistent/foo' does not exist or is not a directory. EOF test_expect_equal_file EXPECTED OUTPUT -- 2.35.2