const char **database_path,
char **message)
{
+ notmuch_status_t status;
+
if (! *database_path) {
*database_path = getenv ("NOTMUCH_DATABASE");
}
}
}
if (! *database_path) {
- notmuch_status_t status;
-
*database_path = _xdg_dir (notmuch, "XDG_DATA_HOME", ".local/share", profile);
status = _db_dir_exists (*database_path, message);
if (status) {
}
if (! *database_path) {
- notmuch_status_t status;
-
*database_path = talloc_asprintf (notmuch, "%s/mail", getenv ("HOME"));
status = _db_dir_exists (*database_path, message);
if (status) {
*message = strdup ("Error: Database path must be absolute.\n");
return NOTMUCH_STATUS_PATH_ERROR;
}
+
+ status = _db_dir_exists (*database_path, message);
+ if (status) {
+ IGNORE_RESULT (asprintf (message,
+ "Error: database path '%s' does not exist or is not a directory.\n",
+ *database_path));
+ return NOTMUCH_STATUS_NO_DATABASE;
+ }
+
+ return NOTMUCH_STATUS_SUCCESS;
+}
+
+static notmuch_status_t
+_mkdir (const char *path, char **message)
+{
+ if (g_mkdir_with_parents (path, 0755)) {
+ IGNORE_RESULT (asprintf (message, "Error: Cannot create directory %s: %s.\n",
+ path, strerror (errno)));
+ return NOTMUCH_STATUS_FILE_ERROR;
+ }
return NOTMUCH_STATUS_SUCCESS;
}
+
static notmuch_database_t *
_alloc_notmuch (const char *database_path, const char *config_path, const char *profile)
{
const char *notmuch_path = NULL;
char *message = NULL;
GKeyFile *key_file = NULL;
- int err;
_notmuch_init ();
&database_path, &message)))
goto DONE;
- status = _db_dir_exists (database_path, &message);
- if (status)
- goto DONE;
-
_set_database_path (notmuch, database_path);
if (key_file && ! (notmuch->params & NOTMUCH_PARAM_SPLIT)) {
goto DONE;
}
- err = mkdir (notmuch_path, 0755);
- if (err) {
- 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;
- }
- }
+ status = _mkdir (notmuch_path, &message);
+ if (status)
+ goto DONE;
}
if (! (notmuch->xapian_path = talloc_asprintf (notmuch, "%s/%s", notmuch_path, "xapian"))) {