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; } _______________________________________________ notmuch mailing list -- notmuch@notmuchmail.org To unsubscribe send an email to notmuch-leave@notmuchmail.org