mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-22 02:48:08 +01:00
lib/open: factor out library initialization
This is slightly more tidy, but more importantly it allows for re-use of this code in n_d_create_with_config. That re-use will be crucial when we no longer call n_d_open_with_config from n_d_create_with_config.
This commit is contained in:
parent
6251e2bb9e
commit
82aa3f4d27
1 changed files with 22 additions and 12 deletions
34
lib/open.cc
34
lib/open.cc
|
@ -220,6 +220,24 @@ _set_database_path (notmuch_database_t *notmuch,
|
||||||
_notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path);
|
_notmuch_config_cache (notmuch, NOTMUCH_CONFIG_DATABASE_PATH, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
_init_libs ()
|
||||||
|
{
|
||||||
|
|
||||||
|
static int initialized = 0;
|
||||||
|
|
||||||
|
/* Initialize the GLib type system and threads */
|
||||||
|
#if ! GLIB_CHECK_VERSION (2, 35, 1)
|
||||||
|
g_type_init ();
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/* Initialize gmime */
|
||||||
|
if (! initialized) {
|
||||||
|
g_mime_init ();
|
||||||
|
initialized = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
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,
|
||||||
|
@ -237,7 +255,8 @@ notmuch_database_open_with_config (const char *database_path,
|
||||||
int err;
|
int err;
|
||||||
unsigned int version;
|
unsigned int version;
|
||||||
GKeyFile *key_file = NULL;
|
GKeyFile *key_file = NULL;
|
||||||
static int initialized = 0;
|
|
||||||
|
_init_libs ();
|
||||||
|
|
||||||
notmuch = _alloc_notmuch ();
|
notmuch = _alloc_notmuch ();
|
||||||
if (! notmuch) {
|
if (! notmuch) {
|
||||||
|
@ -271,17 +290,6 @@ notmuch_database_open_with_config (const char *database_path,
|
||||||
goto DONE;
|
goto DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Initialize the GLib type system and threads */
|
|
||||||
#if ! GLIB_CHECK_VERSION (2, 35, 1)
|
|
||||||
g_type_init ();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Initialize gmime */
|
|
||||||
if (! initialized) {
|
|
||||||
g_mime_init ();
|
|
||||||
initialized = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
std::string last_thread_id;
|
std::string last_thread_id;
|
||||||
std::string last_mod;
|
std::string last_mod;
|
||||||
|
@ -467,6 +475,8 @@ notmuch_database_create_with_config (const char *database_path,
|
||||||
int err;
|
int err;
|
||||||
void *local = talloc_new (NULL);
|
void *local = talloc_new (NULL);
|
||||||
|
|
||||||
|
_init_libs ();
|
||||||
|
|
||||||
if ((status = _choose_database_path (local, config_path, profile,
|
if ((status = _choose_database_path (local, config_path, profile,
|
||||||
&key_file, &database_path, &message)))
|
&key_file, &database_path, &message)))
|
||||||
goto DONE;
|
goto DONE;
|
||||||
|
|
Loading…
Reference in a new issue