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 8FLBFIMXTmBKBwAA0tVLHw (envelope-from ) for ; Sun, 14 Mar 2021 14:02:43 +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 +EiVEIMXTmB+KQAA1q6Kng (envelope-from ) for ; Sun, 14 Mar 2021 14:02:43 +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 CF45712B0B for ; Sun, 14 Mar 2021 15:02:42 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 45F3527585; Sun, 14 Mar 2021 10:02:29 -0400 (EDT) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id E20E92755A for ; Sun, 14 Mar 2021 10:02:22 -0400 (EDT) Received: by fethera.tethera.net (Postfix, from userid 1001) id D97475FA96; Sun, 14 Mar 2021 10:02:22 -0400 (EDT) Received: (nullmailer pid 183663 invoked by uid 1000); Sun, 14 Mar 2021 14:02:19 -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: Sun, 14 Mar 2021 11:02:10 -0300 Message-Id: <20210314140217.183425-16-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210314140217.183425-1-david@tethera.net> References: <20210314140217.183425-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: CBYVE2GJQ2LDJ5YT463FLNXNFNX4PGQR X-Message-ID-Hash: CBYVE2GJQ2LDJ5YT463FLNXNFNX4PGQR 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=1615730563; 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=7uvFmcExCthnYsnxNRzpU6xwvsqkVbSSrdbhjB6oNAc=; b=VlIOWSZlZzgqvZlv6pvM7sJ1I4ZGFzqsM5L1GjoM0OQSFWqQPpyEG/X8rg8fS6p5h0ds82 v+SMHiTa0SI9RcR3DoRy8EiqQ7lrIyzUg+ClOLGmbna8Dk9WU4poNcfTFhch2cxEX9HWe1 gXwHknn9kcCprdNbP47kBAe+u4sqhDaJp2YLkKsyGLuOKFxTwaEpkqPOuAbAeIamxE7OSx +du8HHpBrxWcf6mgDfxillPaVImPBSO4nvUo8slbIzoHGR1m7hksfQEeBMoOyvnwS3Zf0k zfMIMDup2DbQQmPv2SqR7LiPKGAkhunAU4EFpWFnYBQ9QhLL4VPV9BmzLyID7Q== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615730563; a=rsa-sha256; cv=none; b=uSZXspDpd/CMY/Cj+X/JJprHoEO5gq69lnL/wHOlomYkZFmkOJwumNq3tETsHenH/kMK3i 4W9rG1sML7UXVmCWeisgCSrRXrCtq0LPNtWLWvYPdVfG2XLchAwDZs8qbVlFH0/I90Q1Ok Xkr9zS6NwgnCx9OLrknedUPC4LpcSm0WoTOUjcYxhZqvtXo3HJNOzd3ZKxtYVQp7RTx2ld RwwgPOCljiNjzfoTlDVZId7pio77kmpruZLKDvSQPdp5tzeNOMqajXsgx8XgQzYl68XM4I G0Cw46ljR+BZv5J+poNMjGSRtMqQlfny1izuiQy4yUG9jVBGL7MA0wHmZx1+Tw== 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: -1.00 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: CF45712B0B X-Spam-Score: -1.00 X-Migadu-Scanner: scn0.migadu.com X-TUID: 3ZHXipgbAHFm The main functionality will be tested when notmuch-new is converted to support split configuration. Here only the somewhat odd case of split mail root which is actually symlinked to the database path is tested. --- 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 fe42f7f0..2816f72a 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -545,11 +545,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 (); @@ -571,20 +572,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"))) { @@ -592,6 +611,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