Although this increases code duplication, it also increases
flexibility in handling various combinations of missing config file
and missing database.
static notmuch_status_t
_choose_database_path (void *ctx,
static notmuch_status_t
_choose_database_path (void *ctx,
- const char *config_path,
const char **database_path,
bool *split,
char **message)
{
const char **database_path,
bool *split,
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) {
*database_path = getenv ("NOTMUCH_DATABASE");
}
if (! *database_path) {
*database_path = getenv ("NOTMUCH_DATABASE");
}
- if (! *database_path && *key_file) {
- char *path = g_key_file_get_value (*key_file, "database", "path", NULL);
+ if (! *database_path && key_file) {
+ char *path = g_key_file_get_value (key_file, "database", "path", NULL);
if (path) {
*database_path = talloc_strdup (ctx, path);
g_free (path);
if (path) {
*database_path = talloc_strdup (ctx, path);
g_free (path);
- if ((status = _choose_database_path (local, config_path, profile,
- &key_file, &database_path, &split,
+ 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, profile, key_file,
+ &database_path, &split,
+ 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,
- &key_file, &database_path, &split,
- &message)))
+ if ((status = _choose_database_path (local, profile, key_file,
+ &database_path, &split, &message)))
goto DONE;
status = _db_dir_exists (database_path, &message);
goto DONE;
status = _db_dir_exists (database_path, &message);