changeset 21158:55e5e1983b8d

lib-index: Fix detecting whether caller synced everything in mailbox. When mailbox_index_sync_begin() was followed by _commit(), without _next()s in the middle actually syncing the mailbox, the tail_offset was updated to indicate that the mailbox was fully synced. Existing code didn't rely on this, so it probably didn't break anything. This code hasn't worked for a long time, because log_view is always read fully to the end in _sync_begin().
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 18 Nov 2016 01:23:13 +0200
parents a568d6985222
children 569c9a928b26
files src/lib-index/mail-index-sync.c
diffstat 1 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index-sync.c	Tue Nov 15 00:42:27 2016 +0100
+++ b/src/lib-index/mail-index-sync.c	Fri Nov 18 01:23:13 2016 +0200
@@ -26,6 +26,7 @@
 
 	unsigned int no_warning:1;
 	unsigned int seen_nonexternal_transactions:1;
+	unsigned int fully_synced:1;
 };
 
 static void mail_index_sync_add_expunge(struct mail_index_sync_ctx *ctx)
@@ -680,6 +681,7 @@
 	if (i == count) {
 		if (next_i == UINT_MAX) {
 			/* nothing left in sync_list */
+			ctx->fully_synced = TRUE;
 			return FALSE;
 		}
                 ctx->next_uid = next_found_uid;
@@ -773,15 +775,17 @@
 	uint32_t seq;
 	uoff_t offset;
 
-	if (!mail_transaction_log_view_is_last(ctx->view->log_view)) {
-		/* didn't sync everything */
+	if (!ctx->fully_synced) {
+		/* Everything wasn't synced. This usually means that syncing
+		   was used for locking and nothing was synced. Don't update
+		   tail offset. */
 		mail_transaction_log_view_get_prev_pos(ctx->view->log_view,
 						       &seq, &offset);
-	} else {
-		/* synced everything, but we might also have committed new
-		   transactions. include them also here. */
-		mail_transaction_log_get_head(ctx->index->log, &seq, &offset);
+		return;
 	}
+	/* synced everything, but we might also have committed new
+	   transactions. include them also here. */
+	mail_transaction_log_get_head(ctx->index->log, &seq, &offset);
 	mail_transaction_log_set_mailbox_sync_pos(ctx->index->log, seq, offset);
 
 	/* If tail offset has changed, make sure it gets written to