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 8EjzBXANRWCxZgAA0tVLHw (envelope-from ) for ; Sun, 07 Mar 2021 17:29:20 +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 AFrlAXANRWBKVQAA1q6Kng (envelope-from ) for ; Sun, 07 Mar 2021 17:29:20 +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) server-digest SHA256) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 65E5B149E4 for ; Sun, 7 Mar 2021 18:29:19 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id 7B66726BB1; Sun, 7 Mar 2021 12:28:26 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [IPv6:2607:5300:60:c5::1]) by mail.notmuchmail.org (Postfix) with ESMTP id 31D3E27D43 for ; Sun, 7 Mar 2021 12:27:57 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 297BB5FA96; Sun, 7 Mar 2021 12:27:57 -0500 (EST) Received: (nullmailer pid 1091664 invoked by uid 1000); Sun, 07 Mar 2021 17:27:38 -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, 7 Mar 2021 13:27:27 -0400 Message-Id: <20210307172734.1091264-16-david@tethera.net> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20210307172734.1091264-1-david@tethera.net> References: <20210307172734.1091264-1-david@tethera.net> MIME-Version: 1.0 Message-ID-Hash: WJRUSFRPCAZCUE6CHM4VJRL5W2ZLUNCS X-Message-ID-Hash: WJRUSFRPCAZCUE6CHM4VJRL5W2ZLUNCS 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=1615138159; 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=RN8vvsRPtPyJoSq/LaApwdWHOAsi2FJxZyDhctanF+I=; b=ouwPEIj1nb6punmGI+9h+3EVf2Rf7n4KEpx7FInKlVNqy/lO5p8NB6DYgduM025nghOuiM SCI/0aUqteKq85zx8FH2mvG3W1MjUQBtoynZ6D2EsN2CD4YVF6w+Eoyqx05vEPFNDeNr5D SoIg+zbF5vG8G4gw3lAm30SkmD2F4gy0xmOxBrvz/OmIoYrCThhmEhJ8FyZpjiATELL+IH eyoIdC5UJCntcHoOl/GgYE2dBQSXBXslf9fHC2UPMdGf8P/6DvLpSuyIB5QdbomACvF/he OrEjeKyCNF4+u1Tl25iUE5y95QIlOYvO2diQV94A7/Dj80rNIc++4ahnweEtMA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615138159; a=rsa-sha256; cv=none; b=TqUsj76k+t9J2mCFT/9t6Th/kPxDRotZ7TrktukFyRSbAs26/4pXtw+A2dFx+08i4eIW5i qCevRokhtIy3aHtDWVOQD1Nv+dnXf73kA3B/rEQiebLNWVdQBEPEZtNBXdX0NrmRp37Ss4 fEbwopG0xDFWZAC6iGagze6ABTRDrh47/vAfOCnqFmMHRsBGQ5zPQBPWUTbkNZSAEaL+gR crE0Njq7qyoc2tGcwqFMmMgqMNtpWhy7Q3yoVAA8C64qijSWLREq1Y/j19qe+0KiZ5JYpO Iwgy85yXKaZzOPBamTetXKDr50kSkQkxtDRNz2/N3rtsV4dx6lysNG0p1zUpsQ== ARC-Authentication-Results: i=1; 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-Spam-Score: -1.08 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: 65E5B149E4 X-Spam-Score: -1.08 X-Migadu-Scanner: scn1.migadu.com X-TUID: mxf9PvB2ed4v 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 c881f45f..1ad026fb 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -541,11 +541,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 (); @@ -565,20 +566,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"))) { @@ -586,6 +605,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