From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id +G37OXLhQGAgLQAA0tVLHw (envelope-from ) for ; Thu, 04 Mar 2021 13:32:34 +0000 Received: from aspmx2.migadu.com ([2001:41d0:2:c151::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id UATBNXLhQGDsVwAAB5/wlQ (envelope-from ) for ; Thu, 04 Mar 2021 13:32:34 +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)) (No client certificate requested) by aspmx2.migadu.com (Postfix) with ESMTPS id 5CC2E25E4E for ; Thu, 4 Mar 2021 14:32:34 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id EE88C27C65; Thu, 4 Mar 2021 08:31:57 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 584E927579 for ; Thu, 4 Mar 2021 08:31:40 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 5031D5FA96; Thu, 4 Mar 2021 08:31:40 -0500 (EST) Received: (nullmailer pid 4053574 invoked by uid 1000); Thu, 04 Mar 2021 13:31:28 -0000 From: David Bremner To: notmuch@notmuchmail.org Cc: David Bremner Subject: [PATCH 15/22] lib/open: check for split configuration when creating database. Date: Thu, 4 Mar 2021 09:31:18 -0400 Message-Id: <20210304133125.4050229-16-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210304133125.4050229-1-david@tethera.net> References: <20210304133125.4050229-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: MVDWCK67XVGIMVXQK4P5RKGF64PCW4GA X-Message-ID-Hash: MVDWCK67XVGIMVXQK4P5RKGF64PCW4GA 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=1614864754; 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=QYhXdjnbZutUalBe6FJhny6lVkfDbG8a/I8U9XWcHJ8=; b=qyiD0EvIOme/qKNa70hceyXNNOz71aknLJ3AI7wSjXv71L9/cgPGYBi3eq0Bf63hTF4VFF 5SRh7qS7zcQ8bR8rWv6oXPdJ6KRvEd7ho3VOcBDGXccE1iZxPHxQM9kx2OFR7GfNivwCG7 Bv+lwPNTfhsM53EkwUqeM51M+lGU/WwtS5ArI0rQgzWccbWDTljslCWAmJMUxYnPIGKr5u oa/0t/1ny8U3vs5M5Bh6qrMIxWFuRty8KvozrkEVy7Scqlj8E3HkDmsf7Vu5a2L55KLYq7 PruxJd5DobqjtuiSNMCTxi9FPbvd24zxVZVTq/zvo/UGguKmrjXhdjfTOuJJTg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1614864754; a=rsa-sha256; cv=none; b=UnMfUmZVuQeqqCX3eXZaw3PKikrh2CH/baaksV1c9rQkX6jzb/dLiArhi8V65F1WBM7n/6 lonsVCB5ExX/bXK7AjvNMP/kyT139raFb2ZFwvYO8HhaGaMS/9lq5KLaLK9IlgscjkDLTh SPLgMdHrCsbpVVhWh3AJIVNniQXET4kgHQi9rgeSdbF7LwXl0U/wEtw++Ty8UhEF7Dhx23 NuN8F6RQBmwozWYOAN22V2yptu5AU+NUIrG0s6IkvE53WTGNwA8KwxKm/RfAMe+1zSJWzR UMZjkgZL9fe30VyXoHk7XNtJ5+EH34jOmzfewr5QA52PHZWDaziasrIShVheeg== ARC-Authentication-Results: i=1; aspmx2.migadu.com; dkim=none; spf=pass (aspmx2.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.96 Authentication-Results: aspmx2.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx2.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: 5CC2E25E4E X-Spam-Score: -0.96 X-Migadu-Scanner: scn0.migadu.com X-TUID: 4xTxrlvVdXkH 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.1