From: Timo Sirainen Date: Mon, 26 Jun 2017 16:30:11 +0000 (+0300) Subject: lib-storage: Check for storage existence from index dir with ITERINDEX X-Git-Tag: 2.3.0.rc1~1334 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a62e12ba4afefb302ef87faf6173aef012c3b5d6;p=thirdparty%2Fdovecot%2Fcore.git lib-storage: Check for storage existence from index dir with ITERINDEX The root path creation doesn't really even seem to be necessary, because any mailbox access will automatically mkdir the missing directories anyway. Although writing other files might not work so well, such as mail_attribute_dict that points inside the mail directory. This change simply changes the mailboxes/ directory to be looked up from index directory instead of the mail root directory. It also mkdirs the index/mailboxes/ directory afterwards if it didn't exist. So practically this change shouldn't break anything, since the mailboxes/ directory should always exist for both root and the indexes. --- diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 624960561c..a93c859317 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -227,8 +227,8 @@ mail_storage_get_class(struct mail_namespace *ns, const char *driver, } static int -mail_storage_verify_root(const char *root_dir, bool autocreate, - const char **error_r) +mail_storage_verify_root(const char *root_dir, const char *dir_type, + bool autocreate, const char **error_r) { struct stat st; @@ -247,7 +247,7 @@ mail_storage_verify_root(const char *root_dir, bool autocreate, return -1; } else if (!autocreate) { *error_r = t_strdup_printf( - "Root mail directory doesn't exist: %s", root_dir); + "Root %s directory doesn't exist: %s", dir_type, root_dir); return -1; } else { /* doesn't exist */ @@ -259,12 +259,19 @@ static int mail_storage_create_root(struct mailbox_list *list, enum mail_storage_flags flags, const char **error_r) { - const char *root_dir, *error; + const char *root_dir, *type_name, *error; + enum mailbox_list_path_type type; bool autocreate; int ret; - if (!mailbox_list_get_root_path(list, MAILBOX_LIST_PATH_TYPE_MAILBOX, - &root_dir)) { + if (list->set.iter_from_index_dir) { + type = MAILBOX_LIST_PATH_TYPE_INDEX; + type_name = "index"; + } else { + type = MAILBOX_LIST_PATH_TYPE_MAILBOX; + type_name = "mail"; + } + if (!mailbox_list_get_root_path(list, type, &root_dir)) { /* storage doesn't use directories (e.g. shared root) */ return 0; } @@ -275,7 +282,7 @@ mail_storage_create_root(struct mailbox_list *list, /* we don't need to verify, but since debugging is enabled, check and log if the root doesn't exist */ - if (mail_storage_verify_root(root_dir, FALSE, &error) < 0) { + if (mail_storage_verify_root(root_dir, type_name, FALSE, &error) < 0) { i_debug("Namespace %s: Creating storage despite: %s", list->ns->prefix, error); } @@ -283,12 +290,24 @@ mail_storage_create_root(struct mailbox_list *list, } autocreate = (flags & MAIL_STORAGE_FLAG_NO_AUTOCREATE) == 0; - ret = mail_storage_verify_root(root_dir, autocreate, error_r); + ret = mail_storage_verify_root(root_dir, type_name, autocreate, error_r); if (ret == 0) { - ret = mailbox_list_try_mkdir_root(list, root_dir, + const char *mail_root_dir; + + if (!list->set.iter_from_index_dir) + mail_root_dir = root_dir; + else if (!mailbox_list_get_root_path(list, + MAILBOX_LIST_PATH_TYPE_MAILBOX, &mail_root_dir)) + i_unreached(); + ret = mailbox_list_try_mkdir_root(list, mail_root_dir, MAILBOX_LIST_PATH_TYPE_MAILBOX, error_r); } + if (ret == 0 && list->set.iter_from_index_dir) { + ret = mailbox_list_try_mkdir_root(list, root_dir, + MAILBOX_LIST_PATH_TYPE_INDEX, + error_r); + } return ret < 0 ? -1 : 0; }