dovecot: Don't assert-crash if sync was aborted and it still had...

dovecot at dovecot.org dovecot at dovecot.org
Sat Dec 8 16:40:38 EET 2007


details:   http://hg.dovecot.org/dovecot/rev/07f151520c84
changeset: 6955:07f151520c84
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Dec 08 16:40:34 2007 +0200
description:
Don't assert-crash if sync was aborted and it still had expunges left.

diffstat:

1 file changed, 31 insertions(+), 23 deletions(-)
src/lib-storage/index/index-sync.c |   54 ++++++++++++++++++++----------------

diffs (81 lines):

diff -r aee731c09668 -r 07f151520c84 src/lib-storage/index/index-sync.c
--- a/src/lib-storage/index/index-sync.c	Sat Dec 08 15:59:48 2007 +0200
+++ b/src/lib-storage/index/index-sync.c	Sat Dec 08 16:40:34 2007 +0200
@@ -185,6 +185,30 @@ static bool sync_rec_check_skips(struct 
 	return TRUE;
 }
 
+static int
+index_mailbox_sync_next_expunge(struct index_mailbox_sync_context *ctx,
+				struct mailbox_sync_rec *sync_rec_r)
+{
+	const struct seq_range *range;
+
+	if (ctx->expunge_pos == 0)
+		return 0;
+
+	/* expunges is a sorted array of sequences. it's easiest for
+	   us to print them from end to beginning. */
+	ctx->expunge_pos--;
+	range = array_idx(ctx->expunges, ctx->expunge_pos);
+	i_assert(range->seq2 <= ctx->messages_count);
+
+	index_mailbox_expunge_recent(ctx->ibox, range->seq1, range->seq2);
+	ctx->messages_count -= range->seq2 - range->seq1 + 1;
+
+	sync_rec_r->seq1 = range->seq1;
+	sync_rec_r->seq2 = range->seq2;
+	sync_rec_r->type = MAILBOX_SYNC_TYPE_EXPUNGE;
+	return 1;
+}
+
 bool index_mailbox_sync_next(struct mailbox_sync_context *_ctx,
 			     struct mailbox_sync_rec *sync_rec_r)
 {
@@ -225,29 +249,7 @@ bool index_mailbox_sync_next(struct mail
 			return 1;
 		}
 	}
-
-	if (ctx->expunge_pos > 0) {
-		/* expunges is a sorted array of sequences. it's easiest for
-		   us to print them from end to beginning. */
-		const struct seq_range *range;
-
-		ctx->expunge_pos--;
-		range = array_idx(ctx->expunges, ctx->expunge_pos);
-
-		sync_rec_r->seq1 = range->seq1;
-		sync_rec_r->seq2 = range->seq2;
-		index_mailbox_expunge_recent(ctx->ibox, sync_rec_r->seq1,
-					     sync_rec_r->seq2);
-
-		if (sync_rec_r->seq2 > ctx->messages_count)
-			sync_rec_r->seq2 = ctx->messages_count;
-		ctx->messages_count -= sync_rec_r->seq2 - sync_rec_r->seq1 + 1;
-
-		sync_rec_r->type = MAILBOX_SYNC_TYPE_EXPUNGE;
-		return 1;
-	}
-
-	return 0;
+	return index_mailbox_sync_next_expunge(ctx, sync_rec_r);
 }
 
 static void
@@ -316,9 +318,15 @@ int index_mailbox_sync_deinit(struct mai
 	struct index_mailbox_sync_context *ctx =
 		(struct index_mailbox_sync_context *)_ctx;
 	struct index_mailbox *ibox = ctx->ibox;
+	struct mailbox_sync_rec sync_rec;
 	const struct mail_index_header *hdr;
 	uint32_t seq1, seq2;
 	int ret = ctx->failed ? -1 : 0;
+
+	/* finish handling expunges, so we don't break when updating
+	   recent flags */
+	while (ctx->expunge_pos > 0)
+		index_mailbox_sync_next_expunge(ctx, &sync_rec);
 
 	if (ctx->sync_ctx != NULL) {
 		if (mail_index_view_sync_commit(&ctx->sync_ctx) < 0) {


More information about the dovecot-cvs mailing list