]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
virtual: Make sure index is rewritten when new mailboxes are added
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 21 Jul 2017 16:52:23 +0000 (19:52 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 21 Jul 2017 16:52:23 +0000 (19:52 +0300)
Otherwise multiple bbox->sync_mailbox_idx point to 0 and they keep overwriting
each others in the header. This causes the header to be constantly updated with
wrong contents.

src/plugins/virtual/virtual-storage.h
src/plugins/virtual/virtual-sync.c

index 38c0dc8f49d67303527d4f99ed8d5aa6f5d62950..8c3bbbdb2a374d841b58e115c6b5a90cb6bb022e 100644 (file)
@@ -155,6 +155,7 @@ struct virtual_mailbox {
        bool have_guid_flags_set:1;
        bool have_guids:1;
        bool have_save_guids:1;
+       bool ext_header_rewrite:1;
 };
 
 extern MODULE_CONTEXT_DEFINE(virtual_storage_module,
index aee794b177618d5d83d120b96ff70198a69ff529..a3c439fc31b2e72b6ae5905bfb675d5a6ec2a5a5 100644 (file)
@@ -46,7 +46,6 @@ struct virtual_sync_context {
        uint32_t uid_validity;
 
        bool ext_header_changed:1;
-       bool ext_header_rewrite:1;
        bool expunge_removed:1;
        bool index_broken:1;
 };
@@ -253,6 +252,7 @@ int virtual_mailbox_ext_header_read(struct virtual_mailbox *mbox,
        }
        if (i < ext_mailbox_count) {
                *broken_r = TRUE;
+               mbox->ext_header_rewrite = TRUE;
                ret = 0;
        }
        mbox->highest_mailbox_id = ext_hdr == NULL ? 0 :
@@ -270,6 +270,8 @@ int virtual_mailbox_ext_header_read(struct virtual_mailbox *mbox,
        }
        /* sort the backend mailboxes by mailbox_id. */
        array_sort(&mbox->backend_boxes, bbox_mailbox_id_cmp);
+       if (ret == 0)
+               mbox->ext_header_rewrite = TRUE;
        return ret;
 }
 
@@ -475,7 +477,7 @@ static void virtual_sync_index_finish(struct virtual_sync_context *ctx)
 
        mail_index_view_close(&view);
 
-       if (ctx->ext_header_rewrite) {
+       if (ctx->mbox->ext_header_rewrite) {
                /* entire mailbox list needs to be rewritten */
                virtual_sync_ext_header_rewrite(ctx);
        } else {
@@ -1102,7 +1104,7 @@ static void virtual_sync_backend_ext_header(struct virtual_sync_context *ctx,
        bbox->ondisk_highest_modseq = wanted_ondisk_highest_modseq;
        bbox->sync_next_uid = status.uidnext;
 
-       if (ctx->ext_header_rewrite) {
+       if (ctx->mbox->ext_header_rewrite) {
                /* we'll rewrite the entire header later */
                return;
        }
@@ -1668,6 +1670,7 @@ static int virtual_sync_finish(struct virtual_sync_context *ctx, bool success)
                        mailbox_set_index_error(&ctx->mbox->box);
                        ret = -1;
                }
+               ctx->mbox->ext_header_rewrite = FALSE;
        } else {
                if (ctx->index_broken) {
                        /* make sure we don't complain about the same errors
@@ -1721,8 +1724,6 @@ static int virtual_sync(struct virtual_mailbox *mbox,
        ret = virtual_mailbox_ext_header_read(mbox, ctx->sync_view, &broken);
        if (ret < 0)
                return virtual_sync_finish(ctx, FALSE);
-       if (ret == 0)
-               ctx->ext_header_rewrite = TRUE;
        if (broken)
                ctx->index_broken = TRUE;
        /* apply changes from virtual index to backend mailboxes */