]> 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>
Mon, 24 Jul 2017 09:06:33 +0000 (12:06 +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 5e9ef8f2b85a6eae5a460de42ae71a1f92a8dd00..9a18c1937c6f181ce096e9d5d68a71a8f98f0d18 100644 (file)
@@ -155,6 +155,7 @@ struct virtual_mailbox {
        unsigned int have_guid_flags_set:1;
        unsigned int have_guids:1;
        unsigned int have_save_guids:1;
+       unsigned int ext_header_rewrite:1;
 };
 
 extern MODULE_CONTEXT_DEFINE(virtual_storage_module,
index 62e75e70914a74cce5740d24374f0be6e0ca0780..e6a20cff8f29cf2e484a057a72259e3cbc7f2dc9 100644 (file)
@@ -45,7 +45,6 @@ struct virtual_sync_context {
        uint32_t uid_validity;
 
        unsigned int ext_header_changed:1;
-       unsigned int ext_header_rewrite:1;
        unsigned int expunge_removed:1;
        unsigned int index_broken:1;
 };
@@ -252,6 +251,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 :
@@ -269,6 +269,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;
 }
 
@@ -474,7 +476,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 {
@@ -1101,7 +1103,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;
        }
@@ -1667,6 +1669,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
@@ -1720,8 +1723,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 */