]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-storage: Replace INDEX with mail_index_path setting
authorTimo Sirainen <timo.sirainen@open-xchange.com>
Fri, 27 Oct 2023 20:00:55 +0000 (23:00 +0300)
committerAki Tuomi <aki.tuomi@open-xchange.com>
Wed, 12 Feb 2025 10:34:11 +0000 (12:34 +0200)
Originally:
 * No INDEX specified: mailbox_list_settings.index_dir = NULL,
   i.e. use the default mail directory
 * INDEX=MEMORY: mailbox_list_settings.index_dir = ""

After this commit:
 * mail_index_path = "": Use the default mail directory
 * mail_index_path = MEMORY

17 files changed:
src/lib-index/mail-cache-lookup.c
src/lib-index/mail-cache.h
src/lib-storage/index/dbox-common/dbox-storage.c
src/lib-storage/index/dbox-single/sdbox-storage.c
src/lib-storage/index/imapc/imapc-list.c
src/lib-storage/index/index-mail.c
src/lib-storage/index/pop3c/pop3c-storage.c
src/lib-storage/list/mailbox-list-delete.c
src/lib-storage/list/mailbox-list-delete.h
src/lib-storage/list/mailbox-list-fs.c
src/lib-storage/list/mailbox-list-maildir-iter.c
src/lib-storage/list/mailbox-list-maildir.c
src/lib-storage/mail-storage-settings.c
src/lib-storage/mail-storage-settings.h
src/lib-storage/mail-storage.c
src/lib-storage/mailbox-list.c
src/lib-storage/mailbox-list.h

index e57b40b976518acbc0e2bb96631f744aa1a5ae80..bbb9a98b597609360f9117042024cc8b75d06ede 100644 (file)
@@ -195,7 +195,7 @@ mail_cache_lookup_iter_next_record(struct mail_cache_lookup_iterate_ctx *ctx)
                    view->trans_seq2 < ctx->seq)
                        return 0;
                /* check data still in memory. this works for recent mails
-                  even with INDEX=MEMORY */
+                  even with mail_index_path=MEMORY */
                if (!ctx->memory_appends_checked) {
                        if (mail_cache_lookup_iter_transaction(ctx))
                                return 1;
index 795e0bcad5b9a3f1644c367adacf94d39a0b27b5..e31d9ca15c15a4066c8882c41950f6c1b94f53b8 100644 (file)
@@ -154,7 +154,7 @@ bool mail_cache_field_can_add(struct mail_cache_transaction_ctx *ctx,
                              uint32_t seq, unsigned int field_idx);
 /* Notify cache that the mail is now closed. Any records added with
    mail_cache_add() are unlikely to be required again. This mainly tells
-   INDEX=MEMORY that it can free up the memory used by the mail. */
+   mail_index_path=MEMORY that it can free up the memory used by the mail. */
 void mail_cache_close_mail(struct mail_cache_transaction_ctx *ctx,
                           uint32_t seq);
 
index dda7a59a51d6d094ce481ed4d93c1613aa204f79..dee5a83c80807ed8abe3d54b2f69fa8beb2abcc8 100644 (file)
@@ -230,7 +230,7 @@ int dbox_mailbox_check_existence(struct mailbox *box)
        int ret = -1;
        bool has_log_in_index_dir = FALSE;
 
-       if (box->list->set.index_dir != NULL) {
+       if (box->list->mail_set->mail_index_path[0] != '\0') {
                /* Just because the index directory exists, it doesn't mean
                   that the mailbox is selectable. Check that by seeing if
                   dovecot.index.log exists. If it doesn't, fallback to
index 6fc156f3144ea4c8b95de82f2b6b14341e74bc51..af4ce5bcd8f49ea78d988b92d1f71fd0edc8a251 100644 (file)
@@ -351,8 +351,9 @@ static int sdbox_mailbox_open(struct mailbox *box)
                return 0;
        }
 
-       if (box->list->set.index_dir != NULL && existence_ret == 0) {
-               /* If there is an separate INDEX directory configured but no
+       if (box->list->mail_set->mail_index_path[0] != '\0' &&
+           existence_ret == 0) {
+               /* If there is an separate mail_index_path configured but no
                   index files found for this mailbox, do an index rebuild */
                if (sdbox_sync(mbox, SDBOX_SYNC_FLAG_FORCE_REBUILD) < 0)
                        return -1;
index be5cbf952960160b48d73026412ea9689a58a91c..827e6151ddba570a47a92dca2210ef06833a879c 100644 (file)
@@ -420,11 +420,15 @@ static struct mailbox_list *imapc_list_get_fs(struct imapc_mailbox_list *list)
        struct mailbox_list_settings list_set;
        const char *error, *dir;
 
-       dir = list->list.set.index_dir;
-       if (dir == NULL)
+       if (list->list.mail_set->mail_index_path[0] == '\0')
                dir = list->list.set.root_dir;
+       else if (strcmp(list->list.mail_set->mail_index_path,
+                       MAIL_INDEX_PATH_MEMORY) == 0)
+               dir = "";
+       else
+               dir = list->list.mail_set->mail_index_path;
 
-       if (dir == NULL || dir[0] == '\0') {
+       if (dir[0] == '\0') {
                /* indexes disabled */
        } else if (list->index_list == NULL && !list->index_list_failed) {
                mailbox_list_settings_init_defaults(&list_set);
index c126a171fddd3353a25a64e6e3a821030f32fe14..1daa67cd00609971bbe45f79030ab3c1898b9bb5 100644 (file)
@@ -1916,8 +1916,8 @@ void index_mail_close(struct mail *_mail)
 
        index_mail_close_streams_full(mail, TRUE);
        /* Notify cache that the mail is no longer open. This mainly helps
-          with INDEX=MEMORY to keep all data added with mail_cache_add() in
-          memory until this point. */
+          with mail_index_path=MEMORY to keep all data added with
+          mail_cache_add() in memory until this point. */
        mail_cache_close_mail(_mail->transaction->cache_trans, _mail->seq);
 
        mailbox_header_lookup_unref(&mail->data.wanted_headers);
index bb9d5b34c31e01f549ee77b03d797dd3e7582f18..daaeebf9911f619623e9bf835592a2c865bf2b93 100644 (file)
@@ -105,19 +105,6 @@ pop3c_client_create_from_set(struct mail_storage *storage,
        return pop3c_client_init(&client_set, storage->event);
 }
 
-static void
-pop3c_storage_get_list_settings(const struct mail_namespace *ns ATTR_UNUSED,
-                               struct mailbox_list_settings *set,
-                               const struct mail_storage_settings *mail_set ATTR_UNUSED)
-{
-       if (set->root_dir != NULL && *set->root_dir != '\0' &&
-           set->index_dir == NULL) {
-              /* we don't really care about root_dir, but we
-                 just need to get index_dir autocreated. */
-               set->index_dir = set->root_dir;
-       }
-}
-
 static struct mailbox *
 pop3c_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list,
                    const char *vname, enum mailbox_flags flags)
@@ -323,7 +310,7 @@ struct mail_storage pop3c_storage = {
                pop3c_storage_create,
                pop3c_storage_destroy,
                NULL,
-               pop3c_storage_get_list_settings,
+               NULL,
                NULL,
                pop3c_mailbox_alloc,
                NULL,
index 73f5576d33c6e5b82aa564a83be6a052314368d0..a23fe3f9d7838f51a1b200ffdaaebc6eff49fbed 100644 (file)
@@ -266,7 +266,7 @@ static bool mailbox_list_path_is_index(struct mailbox_list *list,
        if (type == MAILBOX_LIST_PATH_TYPE_INDEX)
                return TRUE;
 
-       /* e.g. mail_control_path could point to the same INDEX dir. */
+       /* e.g. mail_control_path could point to the same as mail_index_path. */
        type_root = mailbox_list_get_root_forced(list, type);
        index_root = mailbox_list_get_root_forced(list, MAILBOX_LIST_PATH_TYPE_INDEX);
        return strcmp(type_root, index_root) == 0;
@@ -359,15 +359,15 @@ static int mailbox_list_try_delete(struct mailbox_list *list, const char *name,
            mailbox_list_get_path(list, name, MAILBOX_LIST_PATH_TYPE_INDEX,
                                  &index_path) > 0 &&
            strcmp(index_path, path) == 0) {
-               /* mail_control_path is the same as INDEX dir, which we already
-                  deleted. We don't want to continue especially with
+               /* mail_control_path is the same as mail_index_path, which we
+                  already deleted. We don't want to continue especially with
                   mailbox_list_iter_from_index_dir=yes, because it could be
                   deleting the index directory. */
                return 0;
        }
 
        /* Note that only mail_alt_path currently uses maildir_name in paths.
-          INDEX and mail_control_path don't. */
+          mail_index_path and mail_control_path don't. */
        if (type != MAILBOX_LIST_PATH_TYPE_ALT_MAILBOX ||
            *list->set.maildir_name == '\0') {
                /* this directory may contain also child mailboxes' data.
index af44c3de8ab3527e2f11c116099c297dbdd2619e..e5eeedec197f00dc5051f1b62d3ffdfe4dbb6d2d 100644 (file)
@@ -47,8 +47,8 @@ int mailbox_list_delete_mailbox_file(struct mailbox_list *list,
 int mailbox_list_delete_mailbox_nonrecursive(struct mailbox_list *list,
                                             const char *name, const char *path,
                                             bool rmdir_path);
-/* Lookup INDEX, mail_control_path and mail_alt_path directories for the
-   mailbox and delete them.
+/* Lookup mail_index_path, mail_control_path and mail_alt_path directories
+   for the mailbox and delete them.
    Returns 1 if anything was unlink()ed or rmdir()ed, 0 if not.
    Returns -1 and sets the list error on any errors. */
 int mailbox_list_delete_finish(struct mailbox_list *list, const char *name);
index 86cc3e56a148fe94f82c59abb2121582131fa836..de2dc3d227c3d008ac15fc1f22e738ae59546a00 100644 (file)
@@ -81,7 +81,8 @@ fs_list_get_path(struct mailbox_list *_list, const char *name,
 
        if (mailbox_list_try_get_absolute_path(_list, &name)) {
                if (type == MAILBOX_LIST_PATH_TYPE_INDEX &&
-                   *set->index_dir == '\0')
+                   strcmp(_list->mail_set->mail_index_path,
+                          MAIL_INDEX_PATH_MEMORY) == 0)
                        return 0;
                *path_r = name;
                return 1;
@@ -133,10 +134,12 @@ fs_list_get_path(struct mailbox_list *_list, const char *name,
                }
                /* fall through */
        case MAILBOX_LIST_PATH_TYPE_INDEX:
-               if (set->index_dir != NULL) {
-                       if (*set->index_dir == '\0')
+               if (mail_set->mail_index_path[0] != '\0') {
+                       if (strcmp(mail_set->mail_index_path,
+                                  MAIL_INDEX_PATH_MEMORY) == 0)
                                return 0;
-                       *path_r = fs_list_get_path_to(_list, set->index_dir, name);
+                       *path_r = fs_list_get_path_to(_list,
+                               mail_set->mail_index_path, name);
                        return 1;
                }
                break;
index 7cafac1f3e5c53a13ecfa9ac7dc1492319578bae..bbd4afa13d6ad1a1ec07d3558709ceaf9bc2b438 100644 (file)
@@ -444,7 +444,7 @@ maildir_list_iter_init(struct mailbox_list *_list, const char *const *patterns,
                '\0' : list->sep;
 
        if (_list->mail_set->mailbox_list_iter_from_index_dir)
-               ctx->dir = _list->set.index_dir;
+               ctx->dir = _list->mail_set->mail_index_path;
        else
                ctx->dir = _list->set.root_dir;
 
index 4cea3428f54641b3425c102c74be296fb0dd070c..2f12a4d5004f1783d28e1fe0dba48b8af51cf2d6 100644 (file)
@@ -144,11 +144,12 @@ maildir_list_get_path(struct mailbox_list *_list, const char *name,
                }
                /* fall through */
        case MAILBOX_LIST_PATH_TYPE_INDEX:
-               if (_list->set.index_dir != NULL) {
-                       if (*_list->set.index_dir == '\0')
+               if (_list->mail_set->mail_index_path[0] != '\0') {
+                       if (strcmp(_list->mail_set->mail_index_path,
+                                  MAIL_INDEX_PATH_MEMORY) == 0)
                                return 0;
                        *path_r = maildir_list_get_dirname_path(_list,
-                                               _list->set.index_dir, name);
+                               _list->mail_set->mail_index_path, name);
                        return 1;
                }
                break;
index 6a8cc1ea455e357757b8e667fafb851a3a7b22e4..ace29d83bacc498b1ff3ab6a7d6264ef6dd280a0 100644 (file)
@@ -83,6 +83,7 @@ static const struct setting_define mail_storage_setting_defines[] = {
        DEF(BOOL_HIDDEN, mailbox_list_validate_fs_names),
        DEF(STR_HIDDEN, mailbox_root_directory_name),
        DEF(STR_HIDDEN, mailbox_subscriptions_filename),
+       DEF(STR, mail_index_path),
        DEF(STR, mail_index_private_path),
        DEF(STR_HIDDEN, mail_cache_path),
        DEF(STR, mail_control_path),
@@ -156,6 +157,7 @@ const struct mail_storage_settings mail_storage_default_settings = {
        .mailbox_list_validate_fs_names = TRUE,
        .mailbox_root_directory_name = "",
        .mailbox_subscriptions_filename = "subscriptions",
+       .mail_index_path = "",
        .mail_index_private_path = "",
        .mail_cache_path = "",
        .mail_control_path = "",
@@ -516,6 +518,7 @@ mailbox_list_get_path_setting(const char *key, const char **value,
                const char *set_name;
                enum mailbox_list_path_type type;
        } set_types[] = {
+               { "mail_index_path", MAILBOX_LIST_PATH_TYPE_INDEX },
                { "mail_index_private_path", MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE },
                { "mail_cache_path", MAILBOX_LIST_PATH_TYPE_INDEX_CACHE },
                { "mail_control_path", MAILBOX_LIST_PATH_TYPE_CONTROL },
@@ -750,13 +753,11 @@ mail_storage_settings_ext_check(struct event *event, void *_set, pool_t pool,
                set->parsed_list_index_dir =
                        p_strdup_until(pool, set->mailbox_list_index_prefix, fname);
                set->parsed_list_index_fname = fname+1;
-#if 0 // FIXME: uncomment after mailbox_index_path is converted
                if (set->parsed_list_index_dir[0] != '/' &&
-                   set->mailbox_index_path[0] == '\0') {
-                       *error_r = "mailbox_list_index_prefix directory is relative, but mailbox_index_path is empty";
+                   set->mail_index_path[0] == '\0') {
+                       *error_r = "mailbox_list_index_prefix directory is relative, but mail_index_path is empty";
                        return FALSE;
                }
-#endif
        }
        if (set->mailbox_root_directory_name[0] == '\0')
                set->parsed_mailbox_root_directory_prefix = "";
@@ -1017,6 +1018,7 @@ static const size_t mail_storage_2nd_reset_offsets[] = {
        OFFSET(mailbox_list_iter_from_index_dir),
        OFFSET(mailbox_root_directory_name),
        OFFSET(mailbox_subscriptions_filename),
+       OFFSET(mail_index_path),
        OFFSET(mail_index_private_path),
        OFFSET(mail_cache_path),
        OFFSET(mail_control_path),
index 24eaf61311f5e05fa44bf9cb0d1a850ddb436507..05b8f0c6e7524ab5c60d07bc4bb73e6aff6fdd17 100644 (file)
@@ -5,6 +5,9 @@
 #include "fsync-mode.h"
 #include "mailbox-list.h"
 
+/* mail_index_path setting points to using in-memory indexes */
+#define MAIL_INDEX_PATH_MEMORY "MEMORY"
+
 struct mail_user;
 struct mail_namespace;
 struct mail_storage;
@@ -63,6 +66,7 @@ struct mail_storage_settings {
        bool mailbox_list_validate_fs_names;
        const char *mailbox_root_directory_name;
        const char *mailbox_subscriptions_filename;
+       const char *mail_index_path;
        const char *mail_index_private_path;
        const char *mail_cache_path;
        const char *mail_control_path;
index 3dea06bcb9c570ce8d4fbecb8604b7f8e424ec52..fc6c6ef097945ee731f946dcc18285763035e9eb 100644 (file)
@@ -2166,8 +2166,10 @@ mailbox_lists_rename_compatible(struct mailbox_list *list1,
                        list1->ns->set->name, list2->ns->set->name);
                return FALSE;
        }
-       if (!nullequals(list1->set.index_dir, list2->set.index_dir)) {
-               *error_r = t_strdup_printf("Namespace %s has index dir, %s doesn't",
+       if (!nullequals(list1->mail_set->mail_index_path,
+                       list2->mail_set->mail_index_path)) {
+               *error_r = t_strdup_printf(
+                       "Namespace %s has mail_index_path, %s doesn't",
                        list1->ns->set->name, list2->ns->set->name);
                return FALSE;
        }
index 9fbf55337c72c9e2618947f497959ad1890cbd0e..e81b8858f82a4712b30934c575cc8bad3773d5bf 100644 (file)
@@ -149,12 +149,8 @@ int mailbox_list_create(struct event *event, struct mail_namespace *ns,
                list->props |= MAILBOX_LIST_PROP_NO_NOSELECT;
 
        /* copy settings */
-       if (set->root_dir != NULL) {
+       if (set->root_dir != NULL)
                list->set.root_dir = p_strdup(list->pool, set->root_dir);
-               list->set.index_dir = set->index_dir == NULL ||
-                       strcmp(set->index_dir, set->root_dir) == 0 ? NULL :
-                       p_strdup(list->pool, set->index_dir);
-       }
 
        list->set.inbox_path = p_strdup(list->pool, set->inbox_path);
        list->set.maildir_name =
@@ -183,7 +179,7 @@ int mailbox_list_create(struct event *event, struct mail_namespace *ns,
                "%s: root=%s, index=%s, indexpvt=%s, control=%s, inbox=%s, alt=%s",
                list->name,
                list->set.root_dir == NULL ? "" : list->set.root_dir,
-               list->set.index_dir == NULL ? "" : list->set.index_dir,
+               mail_set->mail_index_path,
                mail_set->mail_index_private_path,
                mail_set->mail_control_path,
                list->set.inbox_path == NULL ?
@@ -289,8 +285,6 @@ mailbox_list_settings_parse_full(struct mail_user *user, const char *data,
 
                if (strcmp(key, "INBOX") == 0)
                        dest = &set_r->inbox_path;
-               else if (strcmp(key, "INDEX") == 0)
-                       dest = &set_r->index_dir;
                else if (strcmp(key, "DIRNAME") == 0)
                        dest = &set_r->maildir_name;
                else if (strcmp(key, "FULLDIRNAME") == 0) {
@@ -312,9 +306,6 @@ mailbox_list_settings_parse_full(struct mail_user *user, const char *data,
                        return -1;
                }
        }
-
-       if (set_r->index_dir != NULL && strcmp(set_r->index_dir, "MEMORY") == 0)
-               set_r->index_dir = "";
        return 0;
 }
 
@@ -365,6 +356,9 @@ const char *mailbox_list_get_unexpanded_path(struct mailbox_list *list,
        case MAILBOX_LIST_PATH_TYPE_CONTROL:
                type = MAILBOX_LIST_PATH_TYPE_DIR;
                break;
+       case MAILBOX_LIST_PATH_TYPE_INDEX:
+               type = MAILBOX_LIST_PATH_TYPE_DIR;
+               break;
        case MAILBOX_LIST_PATH_TYPE_LIST_INDEX:
                type = MAILBOX_LIST_PATH_TYPE_INDEX;
                break;
@@ -1400,15 +1394,6 @@ mailbox_list_set_get_root_path(const struct mailbox_list_settings *set,
        case MAILBOX_LIST_PATH_TYPE_INDEX_CACHE:
                break;
        case MAILBOX_LIST_PATH_TYPE_INDEX:
-               if (set->index_dir != NULL) {
-                       if (set->index_dir[0] == '\0') {
-                               /* in-memory indexes */
-                               return 0;
-                       }
-                       path = set->index_dir;
-               } else {
-                       path = set->root_dir;
-               }
                break;
        case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE:
                break;
@@ -1442,6 +1427,18 @@ bool mailbox_list_default_get_root_path(struct mailbox_list *list,
                path = mail_set->mail_control_path[0] != '\0' ?
                        mail_set->mail_control_path : list->set.root_dir;
                break;
+       case MAILBOX_LIST_PATH_TYPE_INDEX:
+               if (mail_set->mail_index_path[0] != '\0') {
+                       if (strcmp(mail_set->mail_index_path,
+                                  MAIL_INDEX_PATH_MEMORY) == 0) {
+                               /* in-memory indexes */
+                               return 0;
+                       }
+                       path = mail_set->mail_index_path;
+               } else {
+                       path = list->set.root_dir;
+               }
+               break;
        case MAILBOX_LIST_PATH_TYPE_INDEX_PRIVATE:
                path = mail_set->mail_index_private_path;
                break;
@@ -1451,8 +1448,7 @@ bool mailbox_list_default_get_root_path(struct mailbox_list *list,
                        break;
                }
                /* default to index directory */
-               return mailbox_list_set_get_root_path(&list->set,
-                       list->mail_set->parsed_mailbox_root_directory_prefix,
+               return mailbox_list_default_get_root_path(list,
                        MAILBOX_LIST_PATH_TYPE_INDEX, path_r);
        case MAILBOX_LIST_PATH_TYPE_LIST_INDEX:
                if (mail_set->parsed_list_index_dir != NULL) {
@@ -1461,16 +1457,14 @@ bool mailbox_list_default_get_root_path(struct mailbox_list *list,
                                break;
                        }
                        /* relative path */
-                       if (!mailbox_list_set_get_root_path(&list->set,
-                                       list->mail_set->parsed_mailbox_root_directory_prefix,
+                       if (!mailbox_list_default_get_root_path(list,
                                        MAILBOX_LIST_PATH_TYPE_INDEX, &path))
                                i_unreached();
                        path = t_strconcat(path, "/",
                                mail_set->parsed_list_index_dir, NULL);
                }
                /* default to index directory */
-               return mailbox_list_set_get_root_path(&list->set,
-                       list->mail_set->parsed_mailbox_root_directory_prefix,
+               return mailbox_list_default_get_root_path(list,
                        MAILBOX_LIST_PATH_TYPE_INDEX, path_r);
        default:
                return mailbox_list_set_get_root_path(&list->set,
index e2a9a5258079847af4042efda2fbb89187b13676..040f00872c0575e2a2ccb90182578a916fb7f5ba 100644 (file)
@@ -115,7 +115,6 @@ enum mailbox_list_get_storage_flags {
 
 struct mailbox_list_settings {
        const char *root_dir;
-       const char *index_dir;
 
        const char *inbox_path;
        /* If non-empty, it means that mails exist in a maildir_name