From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id gGQWHj7W81/JJAAA0tVLHw (envelope-from ) for ; Tue, 05 Jan 2021 03:00:14 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id GBrcGT7W81+AbgAA1q6Kng (envelope-from ) for ; Tue, 05 Jan 2021 03:00:14 +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) server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 22E419403A2 for ; Tue, 5 Jan 2021 03:00:14 +0000 (UTC) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 57C2828C8F; Mon, 4 Jan 2021 22:00:08 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id CA44027C7D for ; Mon, 4 Jan 2021 22:00:05 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id D26E56066F; Mon, 4 Jan 2021 21:24:12 -0500 (EST) Received: (nullmailer pid 644508 invoked by uid 1000); Tue, 05 Jan 2021 02:24:06 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 5/5] lib/open: support XDG_DATA_HOME as a fallback database location. Date: Mon, 4 Jan 2021 22:23:50 -0400 Message-Id: <20210105022350.643917-6-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: FWXJOWPJ4SUKHJFM7AIXAASEFYFHW5O2 X-Message-ID-Hash: FWXJOWPJ4SUKHJFM7AIXAASEFYFHW5O2 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.44 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: 22E419403A2 X-Spam-Score: 0.44 X-Migadu-Scanner: scn1.migadu.com X-TUID: xDQiieSs3mO6 This changes some error reporting, either intentionally by reporting the highest level missing directory, or by side effect from looking in XDG locations when given null database location. --- lib/open.cc | 25 +++++++++++++++++++------ test/T055-path-config.sh | 11 +++++++++++ test/T560-lib-error.sh | 6 +++--- test/T590-libconfig.sh | 4 ++-- 4 files changed, 35 insertions(+), 11 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 91b24e38..bc97e178 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -116,7 +116,8 @@ DONE: } static notmuch_status_t -_pre_open(const char *config_path, +_pre_open(void *ctx, + const char *config_path, const char *profile, GKeyFile **key_file, const char **database_path, @@ -133,6 +134,10 @@ _pre_open(const char *config_path, if (! *database_path && *key_file) *database_path = g_key_file_get_value (*key_file, "database", "path", NULL); + if (! *database_path) { + *database_path = _xdg_dir (ctx, "XDG_DATA_HOME", ".local/share", profile); + } + if (*database_path == NULL) { *message = strdup ("Error: Cannot open a database for a NULL path.\n"); return NOTMUCH_STATUS_NULL_POINTER; @@ -169,7 +174,7 @@ notmuch_database_open_with_config (const char *database_path, database_path = getenv ("NOTMUCH_DATABASE"); } - if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message))) + if ((status = _pre_open (local, config_path, profile, &key_file, &database_path, &message))) goto DONE; /* Initialize the GLib type system and threads */ @@ -195,6 +200,14 @@ notmuch_database_open_with_config (const char *database_path, notmuch->view = 1; notmuch->xapian_db = NULL; + err = stat (database_path, &st); + if (err) { + IGNORE_RESULT (asprintf (&message, "Error opening database at %s: %s\n", + database_path, strerror (errno))); + status = NOTMUCH_STATUS_FILE_ERROR; + goto DONE; + } + try { xapian_path = talloc_asprintf (notmuch,"%s/xapian",database_path); notmuch->xapian_db = new Xapian::Database (xapian_path); @@ -408,8 +421,9 @@ notmuch_database_create_with_config (const char *database_path, GKeyFile *key_file = NULL; struct stat st; int err; + void *local = talloc_new (NULL); - if ((status = _pre_open (config_path, profile, &key_file, &database_path, &message))) + if ((status = _pre_open (local, config_path, profile, &key_file, &database_path, &message))) goto DONE; err = stat (database_path, &st); @@ -428,7 +442,7 @@ notmuch_database_create_with_config (const char *database_path, goto DONE; } - notmuch_path = talloc_asprintf (NULL, "%s/%s", database_path, ".notmuch"); + notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"); err = mkdir (notmuch_path, 0755); if (err) { @@ -464,8 +478,7 @@ notmuch_database_create_with_config (const char *database_path, } DONE: - if (notmuch_path) - talloc_free (notmuch_path); + talloc_free (local); if (message) { if (status_string) diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh index 72c369cb..b4bc6741 100755 --- a/test/T055-path-config.sh +++ b/test/T055-path-config.sh @@ -49,4 +49,15 @@ output=$(notmuch count '*') test_expect_equal "$output" '52' restore_database +backup_database +test_begin_subtest "xdg database location" +notmuch config set database.mail_root `pwd`/mail +notmuch config set database.path +dir=home/.local/share/notmuch/default/ +mkdir -p $dir +mv mail/.notmuch/xapian $dir +output=$(notmuch count '*') +test_expect_equal "$output" '52' +restore_database + test_done diff --git a/test/T560-lib-error.sh b/test/T560-lib-error.sh index ade376ef..9b59fb55 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 a database for a NULL path. +Error opening database at CWD/home/.local/share/notmuch/default: No such file or directory EOF test_expect_equal_file EXPECTED OUTPUT @@ -76,7 +76,7 @@ EOF cat <<'EOF' >EXPECTED == stdout == == stderr == -Error opening database at CWD/nonexistent/foo/.notmuch: No such file or directory +Error opening database at CWD/nonexistent/foo: No such file or directory EOF test_expect_equal_file EXPECTED OUTPUT @@ -93,7 +93,7 @@ EOF cat <<'EOF' >EXPECTED == stdout == == stderr == -Error: Cannot open a database for a NULL path. +Error: Cannot create database at CWD/home/.local/share/notmuch/default: No such file or directory. EOF test_expect_equal_file EXPECTED OUTPUT diff --git a/test/T590-libconfig.sh b/test/T590-libconfig.sh index b03ee0c6..256b9463 100755 --- a/test/T590-libconfig.sh +++ b/test/T590-libconfig.sh @@ -487,8 +487,8 @@ cat <<'EOF' >EXPECTED == stdout == == stderr == error opening database -Erroneous NULL pointer -Error: Cannot open a database for a NULL path. +Something went wrong trying to read or write a file +Error opening database at CWD/home/.local/share/notmuch/default: No such file or directory EOF test_expect_equal_file EXPECTED OUTPUT -- 2.29.2