]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Check for storage existence from index dir with ITERINDEX
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 26 Jun 2017 16:30:11 +0000 (19:30 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 3 Jul 2017 12:25:27 +0000 (15:25 +0300)
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.

src/lib-storage/mail-storage.c

index fe123f2e092c1c973e0a76316088f42306cdae2a..274b9f7b6e27eb90c56b0a8f51f55f582df7289e 100644 (file)
@@ -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;
 
@@ -243,7 +243,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 */
@@ -255,12 +255,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;
        }
@@ -271,7 +278,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);
                }
@@ -279,12 +286,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;
 }