From: David Bremner <david@tethera.net>
To: notmuch@notmuchmail.org
Subject: v3 support flexible database location
Date: Sun, 7 Mar 2021 13:27:12 -0400 [thread overview]
Message-ID: <20210307172734.1091264-1-david@tethera.net> (raw)
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;
}
next reply other threads:[~2021-03-07 17:27 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-07 17:27 David Bremner [this message]
2021-03-07 17:27 ` [PATCH 01/22] test/setup: add check for config exists, but no database David Bremner
2021-03-07 17:27 ` [PATCH 02/22] lib: publish API for notmuch_database_reopen David Bremner
2021-03-07 17:27 ` [PATCH 03/22] lib: save path of xapian database in notmuch struct David Bremner
2021-03-07 17:27 ` [PATCH 04/22] lib: support reopening databases for write access David Bremner
2021-03-07 17:27 ` [PATCH 05/22] CLI/show: complete conversion to new configuration framework David Bremner
2021-03-07 17:27 ` [PATCH 06/22] lib/open: support NOTMUCH_DATABASE environment variable David Bremner
2021-03-07 17:27 ` [PATCH 07/22] lib/open: allocate notmuch_t struct early David Bremner
2021-03-07 17:27 ` [PATCH 08/22] lib: remove "path" from notmuch struct David Bremner
2021-03-07 17:27 ` [PATCH 09/22] lib/open: factor out library initialization David Bremner
2021-03-07 17:27 ` [PATCH 10/22] lib/open: reuse directory checks from n_d_c_with_config David Bremner
2021-03-07 17:27 ` [PATCH 11/22] lib/open: factor out the second half of n_d_open_with_config David Bremner
2021-03-07 17:27 ` [PATCH 12/22] lib/open: use _finish_open in n_d_create_with_config David Bremner
2021-03-07 17:27 ` [PATCH 13/22] lib/open: Use check for existing database by trial opening David Bremner
2021-03-07 17:27 ` [PATCH 14/22] support splitting mail from database location David Bremner
2021-03-07 17:27 ` [PATCH 15/22] lib/open: check for split configuration when creating database David Bremner
2021-03-07 17:27 ` [PATCH 16/22] CLI/new: support split database and mail location David Bremner
2021-03-07 17:27 ` [PATCH 17/22] lib/open: support XDG_DATA_HOME as a fallback database location David Bremner
2021-03-07 17:27 ` [PATCH 18/22] CLI/insert: support split database and mail root David Bremner
2021-03-07 17:27 ` [PATCH 19/22] lib/compact: enable split config David Bremner
2021-03-07 17:27 ` [PATCH 20/22] lib/open: fix hook directory calculation in split configuration David Bremner
2021-03-07 17:27 ` [PATCH 21/22] lib/config: add configuration variable for backup directory David Bremner
2021-03-07 17:27 ` [PATCH 22/22] CLI/new: use " David Bremner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://notmuchmail.org/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210307172734.1091264-1-david@tethera.net \
--to=david@tethera.net \
--cc=notmuch@notmuchmail.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://yhetil.org/notmuch.git/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).