}
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;
}
_notmuch_init ();
- notmuch = _alloc_notmuch ();
+ notmuch = _alloc_notmuch (database_path, config_path, profile);
if (! notmuch) {
status = NOTMUCH_STATUS_OUT_OF_MEMORY;
goto DONE;
_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;