X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fopen.cc;h=85e46dc78dbb16eddcf340e738a236c8d7b517e1;hb=25e2790e303b6d9334676e3165a92c6084aa3567;hp=4e5d25451aa7a6bb31b190556fe1de9cdcc2043f;hpb=fd0edeb561e5593d8a834fcc74602b2d8c637123;p=notmuch diff --git a/lib/open.cc b/lib/open.cc index 4e5d2545..85e46dc7 100644 --- a/lib/open.cc +++ b/lib/open.cc @@ -190,7 +190,6 @@ _choose_database_path (notmuch_database_t *notmuch, const char *profile, GKeyFile *key_file, const char **database_path, - bool *split, char **message) { if (! *database_path) { @@ -215,7 +214,7 @@ _choose_database_path (notmuch_database_t *notmuch, if (status) { *database_path = NULL; } else { - *split = true; + notmuch->params |= NOTMUCH_PARAM_SPLIT; } } @@ -245,6 +244,18 @@ _choose_database_path (notmuch_database_t *notmuch, 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) { @@ -513,7 +524,6 @@ notmuch_database_open_with_config (const char *database_path, notmuch_database_t *notmuch = NULL; char *message = NULL; GKeyFile *key_file = NULL; - bool split = false; _notmuch_init (); @@ -530,7 +540,7 @@ notmuch_database_open_with_config (const char *database_path, } if ((status = _choose_database_path (notmuch, profile, key_file, - &database_path, &split, + &database_path, &message))) goto DONE; @@ -609,8 +619,6 @@ notmuch_database_create_with_config (const char *database_path, const char *notmuch_path = NULL; char *message = NULL; GKeyFile *key_file = NULL; - int err; - bool split = false; _notmuch_init (); @@ -627,7 +635,7 @@ notmuch_database_create_with_config (const char *database_path, } if ((status = _choose_database_path (notmuch, profile, key_file, - &database_path, &split, &message))) + &database_path, &message))) goto DONE; status = _db_dir_exists (database_path, &message); @@ -636,18 +644,19 @@ notmuch_database_create_with_config (const char *database_path, _set_database_path (notmuch, database_path); - if (key_file && ! split) { + if (key_file && ! (notmuch->params & NOTMUCH_PARAM_SPLIT)) { char *mail_root = notmuch_canonicalize_file_name ( g_key_file_get_string (key_file, "database", "mail_root", NULL)); char *db_path = notmuch_canonicalize_file_name (database_path); - split = (mail_root && (0 != strcmp (mail_root, db_path))); + if (mail_root && (0 != strcmp (mail_root, db_path))) + notmuch->params |= NOTMUCH_PARAM_SPLIT; free (mail_root); free (db_path); } - if (split) { + if (notmuch->params & NOTMUCH_PARAM_SPLIT) { notmuch_path = database_path; } else { if (! (notmuch_path = talloc_asprintf (notmuch, "%s/%s", database_path, ".notmuch"))) { @@ -655,15 +664,9 @@ notmuch_database_create_with_config (const char *database_path, 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"))) { @@ -805,7 +808,6 @@ notmuch_database_load_config (const char *database_path, notmuch_database_t *notmuch = NULL; char *message = NULL; GKeyFile *key_file = NULL; - bool split = false; _notmuch_init (); @@ -828,7 +830,7 @@ notmuch_database_load_config (const char *database_path, } status = _choose_database_path (notmuch, profile, key_file, - &database_path, &split, &message); + &database_path, &message); switch (status) { case NOTMUCH_STATUS_NO_DATABASE: case NOTMUCH_STATUS_SUCCESS: