changeset 22379:55c0069fec20

virtual: Make sure index is rewritten when new mailboxes are added 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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 21 Jul 2017 19:52:23 +0300
parents 2356b44ebec8
children b83a0ed2793a
files src/plugins/virtual/virtual-storage.h src/plugins/virtual/virtual-sync.c
diffstat 2 files changed, 7 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/plugins/virtual/virtual-storage.h	Fri Jul 21 17:01:05 2017 +0300
+++ b/src/plugins/virtual/virtual-storage.h	Fri Jul 21 19:52:23 2017 +0300
@@ -155,6 +155,7 @@
 	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,
--- a/src/plugins/virtual/virtual-sync.c	Fri Jul 21 17:01:05 2017 +0300
+++ b/src/plugins/virtual/virtual-sync.c	Fri Jul 21 19:52:23 2017 +0300
@@ -45,7 +45,6 @@
 	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 @@
 	}
 	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 @@
 	}
 	/* 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 @@
 
 	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 @@
 	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 @@
 			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 @@
 	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 */