mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
lib/open: allocate notmuch_t struct early
This gives more flexibility in restructuring the database opening code.
This commit is contained in:
parent
793d4305d3
commit
1383481d4a
1 changed files with 36 additions and 21 deletions
57
lib/open.cc
57
lib/open.cc
|
@ -192,6 +192,23 @@ _choose_database_path (void *ctx,
|
||||||
return NOTMUCH_STATUS_SUCCESS;
|
return NOTMUCH_STATUS_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
notmuch_database_t *
|
||||||
|
_alloc_notmuch ()
|
||||||
|
{
|
||||||
|
notmuch_database_t *notmuch;
|
||||||
|
|
||||||
|
notmuch = talloc_zero (NULL, notmuch_database_t);
|
||||||
|
if (! notmuch)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
notmuch->exception_reported = false;
|
||||||
|
notmuch->status_string = NULL;
|
||||||
|
notmuch->writable_xapian_db = NULL;
|
||||||
|
notmuch->atomic_nesting = 0;
|
||||||
|
notmuch->view = 1;
|
||||||
|
return notmuch;
|
||||||
|
}
|
||||||
|
|
||||||
notmuch_status_t
|
notmuch_status_t
|
||||||
notmuch_database_open_with_config (const char *database_path,
|
notmuch_database_open_with_config (const char *database_path,
|
||||||
notmuch_database_mode_t mode,
|
notmuch_database_mode_t mode,
|
||||||
|
@ -211,9 +228,18 @@ notmuch_database_open_with_config (const char *database_path,
|
||||||
GKeyFile *key_file = NULL;
|
GKeyFile *key_file = NULL;
|
||||||
static int initialized = 0;
|
static int initialized = 0;
|
||||||
|
|
||||||
if ((status = _choose_database_path (local, config_path, profile, &key_file, &database_path,
|
notmuch = _alloc_notmuch ();
|
||||||
&message)))
|
if (! notmuch) {
|
||||||
|
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
|
||||||
goto DONE;
|
goto DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((status = _choose_database_path (local, config_path, profile,
|
||||||
|
&key_file, &database_path, &message)))
|
||||||
|
goto DONE;
|
||||||
|
|
||||||
|
notmuch->path = talloc_strdup (notmuch, database_path);
|
||||||
|
strip_trailing (notmuch->path, '/');
|
||||||
|
|
||||||
if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
|
if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".notmuch"))) {
|
||||||
message = strdup ("Out of memory\n");
|
message = strdup ("Out of memory\n");
|
||||||
|
@ -229,6 +255,12 @@ notmuch_database_open_with_config (const char *database_path,
|
||||||
goto DONE;
|
goto DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (! (notmuch->xapian_path = talloc_asprintf (notmuch, "%s/%s", notmuch_path, "xapian"))) {
|
||||||
|
message = strdup ("Out of memory\n");
|
||||||
|
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
|
||||||
|
goto DONE;
|
||||||
|
}
|
||||||
|
|
||||||
/* Initialize the GLib type system and threads */
|
/* Initialize the GLib type system and threads */
|
||||||
#if ! GLIB_CHECK_VERSION (2, 35, 1)
|
#if ! GLIB_CHECK_VERSION (2, 35, 1)
|
||||||
g_type_init ();
|
g_type_init ();
|
||||||
|
@ -240,23 +272,6 @@ notmuch_database_open_with_config (const char *database_path,
|
||||||
initialized = 1;
|
initialized = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
notmuch = talloc_zero (NULL, notmuch_database_t);
|
|
||||||
notmuch->exception_reported = false;
|
|
||||||
notmuch->status_string = NULL;
|
|
||||||
notmuch->path = talloc_strdup (notmuch, database_path);
|
|
||||||
|
|
||||||
strip_trailing (notmuch->path, '/');
|
|
||||||
|
|
||||||
notmuch->writable_xapian_db = NULL;
|
|
||||||
notmuch->atomic_nesting = 0;
|
|
||||||
notmuch->view = 1;
|
|
||||||
|
|
||||||
if (! (notmuch->xapian_path = talloc_asprintf (notmuch, "%s/%s", notmuch_path, "xapian"))) {
|
|
||||||
message = strdup ("Out of memory\n");
|
|
||||||
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
|
|
||||||
goto DONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::string last_thread_id;
|
std::string last_thread_id;
|
||||||
std::string last_mod;
|
std::string last_mod;
|
||||||
|
@ -442,8 +457,8 @@ notmuch_database_create_with_config (const char *database_path,
|
||||||
int err;
|
int err;
|
||||||
void *local = talloc_new (NULL);
|
void *local = talloc_new (NULL);
|
||||||
|
|
||||||
if ((status = _choose_database_path (local, config_path, profile, &key_file, &database_path,
|
if ((status = _choose_database_path (local, config_path, profile,
|
||||||
&message)))
|
&key_file, &database_path, &message)))
|
||||||
goto DONE;
|
goto DONE;
|
||||||
|
|
||||||
err = stat (database_path, &st);
|
err = stat (database_path, &st);
|
||||||
|
|
Loading…
Reference in a new issue