From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp0 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id wH9rCZ54LWBvEQAA0tVLHw (envelope-from ) for ; Wed, 17 Feb 2021 20:12:14 +0000 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp0 with LMTPS id sNhEBZ54LWCMKwAA1q6Kng (envelope-from ) for ; Wed, 17 Feb 2021 20:12: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) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 4746521407 for ; Wed, 17 Feb 2021 21:12:13 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id D861226C16; Wed, 17 Feb 2021 15:11:23 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 45F3526A27 for ; Wed, 17 Feb 2021 15:11:02 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 3F1516067D; Wed, 17 Feb 2021 15:11:02 -0500 (EST) Received: (nullmailer pid 2021434 invoked by uid 1000); Wed, 17 Feb 2021 20:10:50 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 14/21] lib/open: check for split configuration when creating database. Date: Wed, 17 Feb 2021 16:10:38 -0400 Message-Id: <20210217201045.2021106-15-david@tethera.net> X-Mailer: git-send-email 2.30.0 In-Reply-To: <20210217201045.2021106-1-david@tethera.net> References: <20210217201045.2021106-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: 3SIU53JXBHQVFUX4VAC4WW2DEWASCFSQ X-Message-ID-Hash: 3SIU53JXBHQVFUX4VAC4WW2DEWASCFSQ 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.47 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: 4746521407 X-Spam-Score: 0.47 X-Migadu-Scanner: scn0.migadu.com X-TUID: bsdp9/6w4FhL This will be tested when notmuch-new is converted to support split configuration. --- lib/open.cc | 53 ++++++++++++++++++++++++++++++---------- test/T055-path-config.sh | 15 ++++++++++-- 2 files changed, 53 insertions(+), 15 deletions(-) diff --git a/lib/open.cc b/lib/open.cc index 2f65198d..0b3b9ca4 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -525,11 +525,12 @@ notmuch_database_create_with_config (const char *database_path, { notmuch_status_t status = NOTMUCH_STATUS_SUCCESS; notmuch_database_t *notmuch = NULL; - char *notmuch_path = NULL; + const char *notmuch_path = NULL; char *message = NULL; GKeyFile *key_file = NULL; void *local = talloc_new (NULL); int err; + bool split = false; _init_libs (); @@ -548,20 +549,38 @@ notmuch_database_create_with_config (const char *database_path, _set_database_path (notmuch, database_path); - notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"); + if (key_file && !split) { + char *mail_root = canonicalize_file_name ( + g_key_file_get_value (key_file, "database", "mail_root", NULL)); + char *db_path = canonicalize_file_name (database_path); - err = mkdir (notmuch_path, 0755); - if (err) { - if (errno == EEXIST) { - status = NOTMUCH_STATUS_DATABASE_EXISTS; - talloc_free (notmuch); - notmuch = NULL; - } else { - IGNORE_RESULT (asprintf (&message, "Error: Cannot create directory %s: %s.\n", - notmuch_path, strerror (errno))); - status = NOTMUCH_STATUS_FILE_ERROR; + split = (mail_root && (0 != strcmp (mail_root, db_path))); + + free(mail_root); + free (db_path); + } + + if (split) { + notmuch_path = database_path; + } else { + if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) { + status = NOTMUCH_STATUS_OUT_OF_MEMORY; + goto DONE; + } + + err = mkdir (notmuch_path, 0755); + if (err) { + if (errno == EEXIST) { + status = NOTMUCH_STATUS_DATABASE_EXISTS; + talloc_free (notmuch); + notmuch = NULL; + } else { + IGNORE_RESULT (asprintf (&message, "Error: Cannot create directory %s: %s.\n", + notmuch_path, strerror (errno))); + status = NOTMUCH_STATUS_FILE_ERROR; + } + goto DONE; } - goto DONE; } if (! (notmuch->xapian_path = talloc_asprintf (notmuch, "%s/%s", notmuch_path, "xapian"))) { @@ -569,6 +588,14 @@ notmuch_database_create_with_config (const char *database_path, goto DONE; } + status = _trial_open (notmuch->xapian_path, &message); + if (status == NOTMUCH_STATUS_SUCCESS) { + notmuch_database_destroy (notmuch); + notmuch = NULL; + status = NOTMUCH_STATUS_DATABASE_EXISTS; + goto DONE; + } + status = _finish_open (notmuch, profile, NOTMUCH_DATABASE_MODE_READ_WRITE, diff --git a/test/T055-path-config.sh b/test/T055-path-config.sh index c6920ca9..19a8a4ab 100755 --- a/test/T055-path-config.sh +++ b/test/T055-path-config.sh @@ -27,9 +27,17 @@ split_config () { DATABASE_PATH=$dir } +symlink_config () { + local dir + backup_config + dir="$TMP_DIRECTORY/link.$test_count" + ln -s $MAIL_DIR $dir + notmuch config set database.path $dir + notmuch config set database.mail_root $MAIL_DIR + unset DATABASE_PATH +} - -for config in traditional split; do +for config in traditional split symlink; do # start each set of tests with a known set of messages add_email_corpus @@ -41,6 +49,9 @@ for config in traditional split; do split_config mv mail/.notmuch/xapian $DATABASE_PATH ;; + symlink) + symlink_config + ;; esac test_begin_subtest "count ($config)" -- 2.30.0