mirror of
https://git.notmuchmail.org/git/notmuch
synced 2025-02-17 23:53:15 +01:00
lib/open: pull _load_key_file out of _choose_database_path
Although this increases code duplication, it also increases flexibility in handling various combinations of missing config file and missing database.
This commit is contained in:
parent
79a4b2e9e7
commit
a3444e873f
1 changed files with 18 additions and 18 deletions
36
lib/open.cc
36
lib/open.cc
|
@ -183,27 +183,18 @@ _db_dir_exists (const char *database_path, char **message)
|
||||||
|
|
||||||
static notmuch_status_t
|
static notmuch_status_t
|
||||||
_choose_database_path (void *ctx,
|
_choose_database_path (void *ctx,
|
||||||
const char *config_path,
|
|
||||||
const char *profile,
|
const char *profile,
|
||||||
GKeyFile **key_file,
|
GKeyFile *key_file,
|
||||||
const char **database_path,
|
const char **database_path,
|
||||||
bool *split,
|
bool *split,
|
||||||
char **message)
|
char **message)
|
||||||
{
|
{
|
||||||
notmuch_status_t status;
|
|
||||||
|
|
||||||
status = _load_key_file (config_path, profile, key_file);
|
|
||||||
if (status) {
|
|
||||||
*message = strdup ("Error: cannot load config file.\n");
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (! *database_path) {
|
if (! *database_path) {
|
||||||
*database_path = getenv ("NOTMUCH_DATABASE");
|
*database_path = getenv ("NOTMUCH_DATABASE");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (! *database_path && *key_file) {
|
if (! *database_path && key_file) {
|
||||||
char *path = g_key_file_get_value (*key_file, "database", "path", NULL);
|
char *path = g_key_file_get_value (key_file, "database", "path", NULL);
|
||||||
if (path) {
|
if (path) {
|
||||||
*database_path = talloc_strdup (ctx, path);
|
*database_path = talloc_strdup (ctx, path);
|
||||||
g_free (path);
|
g_free (path);
|
||||||
|
@ -500,8 +491,14 @@ notmuch_database_open_with_config (const char *database_path,
|
||||||
goto DONE;
|
goto DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((status = _choose_database_path (local, config_path, profile,
|
status = _load_key_file (config_path, profile, &key_file);
|
||||||
&key_file, &database_path, &split,
|
if (status) {
|
||||||
|
message = strdup ("Error: cannot load config file.\n");
|
||||||
|
goto DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((status = _choose_database_path (local, profile, key_file,
|
||||||
|
&database_path, &split,
|
||||||
&message)))
|
&message)))
|
||||||
goto DONE;
|
goto DONE;
|
||||||
|
|
||||||
|
@ -591,11 +588,14 @@ notmuch_database_create_with_config (const char *database_path,
|
||||||
goto DONE;
|
goto DONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
_init_libs ();
|
status = _load_key_file (config_path, profile, &key_file);
|
||||||
|
if (status) {
|
||||||
|
message = strdup ("Error: cannot load config file.\n");
|
||||||
|
goto DONE;
|
||||||
|
}
|
||||||
|
|
||||||
if ((status = _choose_database_path (local, config_path, profile,
|
if ((status = _choose_database_path (local, profile, key_file,
|
||||||
&key_file, &database_path, &split,
|
&database_path, &split, &message)))
|
||||||
&message)))
|
|
||||||
goto DONE;
|
goto DONE;
|
||||||
|
|
||||||
status = _db_dir_exists (database_path, &message);
|
status = _db_dir_exists (database_path, &message);
|
||||||
|
|
Loading…
Add table
Reference in a new issue