changeset 22298:c36d34f5d759

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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Mon, 26 Jun 2017 19:30:11 +0300
parents 08851deea49c
children d8bb722cde68
files src/lib-storage/mail-storage.c
diffstat 1 files changed, 28 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/mail-storage.c	Mon Jun 26 18:50:24 2017 +0300
+++ b/src/lib-storage/mail-storage.c	Mon Jun 26 19:30:11 2017 +0300
@@ -227,8 +227,8 @@
 }
 
 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;
 
@@ -243,7 +243,7 @@
 		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 */
@@ -255,12 +255,19 @@
 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;
 	}
@@ -271,7 +278,7 @@
 
 		/* 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);
 		}
@@ -279,10 +286,22 @@
 	}
 
 	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) {
+		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_MAILBOX,
+						  MAILBOX_LIST_PATH_TYPE_INDEX,
 						  error_r);
 	}
 	return ret < 0 ? -1 : 0;