- err = mkdir (notmuch_path, 0755);
- if (err) {
- if (errno == EEXIST) {
- status = NOTMUCH_STATUS_DATABASE_EXISTS;
- talloc_free (notmuch);
- notmuch = NULL;
- } else {
- IGNORE_RESULT (asprintf (&message, "Error: Cannot create directory %s: %s.\n",
- notmuch_path, strerror (errno)));
- status = NOTMUCH_STATUS_FILE_ERROR;
+ split = (mail_root && (0 != strcmp (mail_root, db_path)));
+
+ free (mail_root);
+ free (db_path);
+ }
+
+ if (split) {
+ notmuch_path = database_path;
+ } else {
+ if (! (notmuch_path = talloc_asprintf (local, "%s/%s", database_path, ".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 {
+ IGNORE_RESULT (asprintf (&message, "Error: Cannot create directory %s: %s.\n",
+ notmuch_path, strerror (errno)));
+ status = NOTMUCH_STATUS_FILE_ERROR;
+ }
+ goto DONE;