From: Timo Sirainen Date: Thu, 17 Nov 2016 23:23:13 +0000 (+0200) Subject: lib-index: Fix detecting whether caller synced everything in mailbox. X-Git-Tag: 2.2.27~110 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2aa182ac91d179b94923eae31941f688fb345736;p=thirdparty%2Fdovecot%2Fcore.git 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(). --- diff --git a/src/lib-index/mail-index-sync.c b/src/lib-index/mail-index-sync.c index 34a9c78c6b..739716e478 100644 --- a/src/lib-index/mail-index-sync.c +++ b/src/lib-index/mail-index-sync.c @@ -26,6 +26,7 @@ struct mail_index_sync_ctx { 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 @@ bool mail_index_sync_next(struct mail_index_sync_ctx *ctx, 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 @@ mail_index_sync_update_mailbox_offset(struct mail_index_sync_ctx *ctx) 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