From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id yC20MhcNRWAzZAAA0tVLHw (envelope-from ) for ; Sun, 07 Mar 2021 17:27:51 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id yFtxLhcNRWCcGAAAbx9fmQ (envelope-from ) for ; Sun, 07 Mar 2021 17:27:51 +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 5501224651 for ; Sun, 7 Mar 2021 18:27:51 +0100 (CET) Received: from nmbug.tethera.net (localhost [127.0.0.1]) by mail.notmuchmail.org (Postfix) with ESMTP id CD8602755F; Sun, 7 Mar 2021 12:27:41 -0500 (EST) Received: from fethera.tethera.net (fethera.tethera.net [198.245.60.197]) by mail.notmuchmail.org (Postfix) with ESMTP id 7F63B26BB1 for ; Sun, 7 Mar 2021 12:27:39 -0500 (EST) Received: by fethera.tethera.net (Postfix, from userid 1001) id 706BE5FA96; Sun, 7 Mar 2021 12:27:39 -0500 (EST) Received: (nullmailer pid 1091629 invoked by uid 1000); Sun, 07 Mar 2021 17:27:38 -0000 From: David Bremner To: notmuch@notmuchmail.org Subject: v3 support flexible database location Date: Sun, 7 Mar 2021 13:27:12 -0400 Message-Id: <20210307172734.1091264-1-david@tethera.net> X-Mailer: git-send-email 2.30.1 MIME-Version: 1.0 Message-ID-Hash: D3LVUZHXQ3ZM62FZDJLH7BNEO3WLAYET X-Message-ID-Hash: D3LVUZHXQ3ZM62FZDJLH7BNEO3WLAYET 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=1615138071; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=dXuXcltRD5cnA87d38Tz0Jx2SGxAQ2Fee7RMIwLeCw8=; b=QLhimBrsXI0U3Gm7NT4Y1lwEznwNptRcgcLz+TxzMCTSwlUOR07fFTi97GZ9Q+tLPsyux3 ghls2Fo/6B6e2w87FpfZBKaN5PYafeMgVBEJWsAGNikhP6mOpLXy1LN/AVlaYdoi15VK4f EFVLPpVfhYMqnBZb/jGWpJL37A9CpOkN3d9JgXo6KM6lolI388QN07Ebt4qdQ62hcni5oB FA9E6DD8Yli555hyFxx2MNXEa++6iQzidV53gv7SUrB17h/8TiqpqhNC6Qc5VLsGGebr5I G2W58bdMATkjI3GUEgg8hVuy77b7wrr68oS8SoOw8i2LOI/aW6gfAteyl9Uh9A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1615138071; a=rsa-sha256; cv=none; b=SVClX5+lFtndnKWCJrFTZhgzMYwkxR/5Wz4TF24dcvuu0w9l/xCKXGI+QJs5/T/XKwhEcF tARZI4d9jXMYfwO4Jd0WcCsGVJ8GpqHbXR/rQoE8aXwJ3EIeMifH2Di4193O9LQZHvAE12 zrZfBN324YjO+McK8p0zsxxON4aFE/Kv1L8WA5QwUI35tKdQd6qXhB/CnggvW047Y5+Vz6 qkr1gW7FphXY0e5mQGlo8Z4qKWarG1vLdfx/eFZ5KjWgLLZAuvz5XLeV4ijgMKgOFzjP3O b/OdqGiXAN5HVb6cVexxXAzhQxBxUs46J7RH/LRieTyz2VLC1AmK8TXbLKk72Q== 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: 5501224651 X-Spam-Score: -1.08 X-Migadu-Scanner: scn1.migadu.com X-TUID: iIgjUUhcSjrE This series obsoletes [0], although it does not contain any functional changes since that series. It is rebased against memory leak [1] and style [2] fixes. It also contains several style fixes of its own, which hopefully makes it less time consuming to review. [0]: id:20210304133125.4050229-1-david@tethera.net [1]: id:20210306134934.491249-1-david@tethera.net [2]: id:20210307171658.1084026-1-david@tethera.net diff --git a/lib/config.cc b/lib/config.cc index 4541fe95..79d33850 100644 --- a/lib/config.cc +++ b/lib/config.cc @@ -503,7 +503,7 @@ void _notmuch_config_cache (notmuch_database_t *notmuch, notmuch_config_key_t key, const char *val) { if (notmuch->config == NULL) - notmuch->config = _notmuch_string_map_create (notmuch); + notmuch->config = _notmuch_string_map_create (notmuch); _notmuch_string_map_set (notmuch->config, _notmuch_config_key_to_string (key), val); } diff --git a/lib/database.cc b/lib/database.cc index 707854b5..491ede5e 100644 --- a/lib/database.cc +++ b/lib/database.cc @@ -610,7 +610,7 @@ notmuch_database_compact_db (notmuch_database_t *notmuch, { void *local; const char *xapian_path, *compact_xapian_path; - const char* path; + const char *path; notmuch_status_t ret = NOTMUCH_STATUS_SUCCESS; struct stat statbuf; bool keep_backup; diff --git a/lib/open.cc b/lib/open.cc index d62fc6ca..5ff7c4b7 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -91,7 +91,7 @@ _choose_dir (notmuch_database_t *notmuch, parent = _xdg_dir (notmuch, xdg_var, xdg_subdir, profile); if (! parent) - return NOTMUCH_STATUS_PATH_ERROR; + return NOTMUCH_STATUS_PATH_ERROR; dir = talloc_asprintf (notmuch, "%s/%s", parent, subdir); @@ -99,7 +99,7 @@ _choose_dir (notmuch_database_t *notmuch, if (err) { if (errno == ENOENT) { char *notmuch_path = dirname (talloc_strdup (notmuch, notmuch->xapian_path)); - dir = talloc_asprintf (notmuch, "%s/%s", notmuch_path, subdir); + dir = talloc_asprintf (notmuch, "%s/%s", notmuch_path, subdir); } else { IGNORE_RESULT (asprintf (message, "Error: Cannot stat %s: %s.\n", dir, strerror (errno))); @@ -199,7 +199,7 @@ _choose_database_path (void *ctx, } if (! *database_path) { - *database_path = getenv ("NOTMUCH_DATABASE"); + *database_path = getenv ("NOTMUCH_DATABASE"); } if (! *database_path && *key_file) { @@ -227,10 +227,13 @@ _choose_database_path (void *ctx, return NOTMUCH_STATUS_SUCCESS; } -notmuch_database_t * _alloc_notmuch() { - notmuch_database_t * notmuch; +notmuch_database_t * +_alloc_notmuch () +{ + notmuch_database_t *notmuch; + notmuch = talloc_zero (NULL, notmuch_database_t); - if (!notmuch) + if (! notmuch) return NULL; notmuch->exception_reported = false; @@ -245,7 +248,7 @@ static notmuch_status_t _trial_open (const char *xapian_path, char **message_ptr) { try { - Xapian::Database db(xapian_path); + Xapian::Database db (xapian_path); } catch (const Xapian::DatabaseOpeningError &error) { IGNORE_RESULT (asprintf (message_ptr, "Cannot open Xapian database at %s: %s\n", @@ -261,8 +264,10 @@ _trial_open (const char *xapian_path, char **message_ptr) return NOTMUCH_STATUS_SUCCESS; } + notmuch_status_t -_notmuch_choose_xapian_path (void *ctx, const char *database_path, const char **xapian_path, char **message_ptr){ +_notmuch_choose_xapian_path (void *ctx, const char *database_path, const char **xapian_path, char **message_ptr) +{ notmuch_status_t status; const char *trial_path, *notmuch_path; @@ -283,7 +288,7 @@ _notmuch_choose_xapian_path (void *ctx, const char *database_path, const char ** trial_path = talloc_asprintf (ctx, "%s/xapian", notmuch_path); status = _trial_open (trial_path, message_ptr); - DONE: + DONE: if (status == NOTMUCH_STATUS_SUCCESS) *xapian_path = trial_path; return status; @@ -291,15 +296,18 @@ _notmuch_choose_xapian_path (void *ctx, const char *database_path, const char ** static void _set_database_path (notmuch_database_t *notmuch, - const char *database_path) { - char *path=talloc_strdup (notmuch, database_path); + const char *database_path) +{ + char *path = talloc_strdup (notmuch, database_path); strip_trailing (path, '/'); _notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path); } -static void _init_libs () { +static void +_init_libs () +{ static int initialized = 0; @@ -437,8 +445,8 @@ _finish_open (notmuch_database_t *notmuch, ".local/share", "backups", &message); - if (status) - goto DONE; + if (status) + goto DONE; status = _notmuch_config_load_defaults (notmuch); if (status) goto DONE; @@ -458,7 +466,7 @@ _finish_open (notmuch_database_t *notmuch, notmuch = NULL; status = NOTMUCH_STATUS_XAPIAN_EXCEPTION; } - DONE: + DONE: if (message_ptr) *message_ptr = message; return status; @@ -482,7 +490,7 @@ notmuch_database_open_with_config (const char *database_path, _init_libs (); notmuch = _alloc_notmuch (); - if (!notmuch) { + if (! notmuch) { status = NOTMUCH_STATUS_OUT_OF_MEMORY; goto DONE; } @@ -588,14 +596,14 @@ notmuch_database_create_with_config (const char *database_path, _set_database_path (notmuch, database_path); - if (key_file && !split) { + 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); split = (mail_root && (0 != strcmp (mail_root, db_path))); - free(mail_root); + free (mail_root); free (db_path); } @@ -679,6 +687,7 @@ notmuch_database_reopen (notmuch_database_t *notmuch, notmuch_database_mode_t new_mode) { notmuch_database_mode_t cur_mode = _notmuch_database_mode (notmuch); + if (notmuch->xapian_db == NULL) { _notmuch_database_log (notmuch, "Cannot reopen closed or nonexistent database\n"); return NOTMUCH_STATUS_ILLEGAL_ARGUMENT; @@ -708,7 +717,7 @@ notmuch_database_reopen (notmuch_database_t *notmuch, } catch (const Xapian::Error &error) { if (! notmuch->exception_reported) { _notmuch_database_log (notmuch, "Error: A Xapian exception reopening database: %s\n", - error.get_msg ().c_str ()); + error.get_msg ().c_str ()); notmuch->exception_reported = true; } return NOTMUCH_STATUS_XAPIAN_EXCEPTION; diff --git a/notmuch-new.c b/notmuch-new.c index 834c36fb..9a89761d 100644 --- a/notmuch-new.c +++ b/notmuch-new.c @@ -1056,7 +1056,7 @@ _maybe_upgrade (notmuch_database_t *notmuch, add_files_state_t *state) err = mkdir (backup_dir, 0755); if (err && errno != EEXIST) { - fprintf(stderr, "Failed to create %s: %s\n", backup_dir, strerror(errno)); + fprintf (stderr, "Failed to create %s: %s\n", backup_dir, strerror (errno)); return EXIT_FAILURE; }