]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Fix detecting whether caller synced everything in mailbox.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Thu, 17 Nov 2016 23:23:13 +0000 (01:23 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 18 Nov 2016 11:55:49 +0000 (13:55 +0200)
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().

src/lib-index/mail-index-sync.c

index 34a9c78c6b8441f4d4a99f6469ee4bbe5046d4d1..739716e4783ce8d6464b794992137e7601138cc5 100644 (file)
@@ -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