}
static notmuch_database_t *
-_alloc_notmuch ()
+_alloc_notmuch (const char *database_path, const char *config_path, const char *profile)
{
notmuch_database_t *notmuch;
notmuch->transaction_count = 0;
notmuch->transaction_threshold = 0;
notmuch->view = 1;
+
+ notmuch->params = NOTMUCH_PARAM_NONE;
+ if (database_path)
+ notmuch->params |= NOTMUCH_PARAM_DATABASE;
+ if (config_path)
+ notmuch->params |= NOTMUCH_PARAM_CONFIG;
+ if (profile)
+ notmuch->params |= NOTMUCH_PARAM_PROFILE;
+
return notmuch;
}
" has a newer database format version (%u) than supported by this\n"
" version of notmuch (%u).\n",
database_path, version, NOTMUCH_DATABASE_VERSION));
- notmuch_database_destroy (notmuch);
- notmuch = NULL;
status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
" requires features (%s)\n"
" not supported by this version of notmuch.\n",
database_path, incompat_features));
- notmuch_database_destroy (notmuch);
- notmuch = NULL;
status = NOTMUCH_STATUS_FILE_ERROR;
goto DONE;
}
} catch (const Xapian::Error &error) {
IGNORE_RESULT (asprintf (&message, "A Xapian exception occurred opening database: %s\n",
error.get_msg ().c_str ()));
- notmuch_database_destroy (notmuch);
- notmuch = NULL;
status = NOTMUCH_STATUS_XAPIAN_EXCEPTION;
}
DONE:
_notmuch_init ();
- notmuch = _alloc_notmuch ();
+ notmuch = _alloc_notmuch (database_path, config_path, profile);
if (! notmuch) {
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;
free (message);
}
+ if (status && notmuch) {
+ notmuch_database_destroy (notmuch);
+ notmuch = NULL;
+ }
+
if (database)
*database = notmuch;
- else
- talloc_free (notmuch);
if (notmuch)
notmuch->open = true;
_notmuch_init ();
- notmuch = _alloc_notmuch ();
+ notmuch = _alloc_notmuch (database_path, config_path, profile);
if (! notmuch) {
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;
err = mkdir (notmuch_path, 0755);
if (err) {
- if (errno == EEXIST) {
- status = NOTMUCH_STATUS_DATABASE_EXISTS;
- talloc_free (notmuch);
- notmuch = NULL;
- } else {
+ if (errno != EEXIST) {
IGNORE_RESULT (asprintf (&message, "Error: Cannot create directory %s: %s.\n",
notmuch_path, strerror (errno)));
status = NOTMUCH_STATUS_FILE_ERROR;
+ goto DONE;
}
- goto DONE;
}
}
else
free (message);
}
+ if (status && notmuch) {
+ notmuch_database_destroy (notmuch);
+ notmuch = NULL;
+ }
+
if (database)
*database = notmuch;
- else
- talloc_free (notmuch);
+
+ if (notmuch)
+ notmuch->open = true;
return status;
}
_notmuch_init ();
- notmuch = _alloc_notmuch ();
+ notmuch = _alloc_notmuch (database_path, config_path, profile);
if (! notmuch) {
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;
if (status_string)
*status_string = message;
+ if (status &&
+ status != NOTMUCH_STATUS_NO_DATABASE
+ && status != NOTMUCH_STATUS_NO_CONFIG) {
+ notmuch_database_destroy (notmuch);
+ notmuch = NULL;
+ }
+
if (database)
*database = notmuch;