Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6674:2637fb191e5e HEAD
Added MAILBOX_SYNC_FLAG_FIX_INCONSISTENT flag. mailbox_sync() uses it
always. If view is invalid or view syncing causes the view to become
invalid, the view is reopened.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 03 Nov 2007 20:35:59 +0200 |
parents | c5e4a7b75586 |
children | a4f475d415d6 |
files | src/lib-storage/index/index-sync.c src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h |
diffstat | 3 files changed, 38 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/index-sync.c Sat Nov 03 20:22:17 2007 +0200 +++ b/src/lib-storage/index/index-sync.c Sat Nov 03 20:35:59 2007 +0200 @@ -100,6 +100,7 @@ struct index_mailbox *ibox = (struct index_mailbox *)box; struct index_mailbox_sync_context *ctx; enum mail_index_view_sync_flags sync_flags = 0; + int i; ctx = i_new(struct index_mailbox_sync_context, 1); ctx->ctx.box = box; @@ -110,16 +111,36 @@ return &ctx->ctx; } - ctx->messages_count = mail_index_view_get_messages_count(ibox->view); + if ((flags & MAILBOX_SYNC_FLAG_FIX_INCONSISTENT) != 0 && + mail_index_view_is_inconsistent(ibox->view)) { + mail_index_view_close(&ibox->view); + ibox->view = mail_index_view_open(ibox->index); + } if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) != 0) sync_flags = MAIL_INDEX_VIEW_SYNC_FLAG_NOEXPUNGES; - if (mail_index_view_sync_begin(ibox->view, sync_flags, - &ctx->sync_ctx) < 0) { - mail_storage_set_index_error(ibox); - ctx->failed = TRUE; - return &ctx->ctx; + for (i = 0;; i++) { + ctx->messages_count = + mail_index_view_get_messages_count(ibox->view); + + if (mail_index_view_sync_begin(ibox->view, sync_flags, + &ctx->sync_ctx) < 0) { + mail_storage_set_index_error(ibox); + ctx->failed = TRUE; + return &ctx->ctx; + } + + if (i == 0 && + (flags & MAILBOX_SYNC_FLAG_FIX_INCONSISTENT) != 0 && + mail_index_view_is_inconsistent(ibox->view)) { + /* index was just reset */ + (void)mail_index_view_sync_commit(&ctx->sync_ctx); + mail_index_view_close(&ibox->view); + ibox->view = mail_index_view_open(ibox->index); + } else { + break; + } } if ((flags & MAILBOX_SYNC_FLAG_NO_EXPUNGES) == 0) {
--- a/src/lib-storage/mail-storage.c Sat Nov 03 20:22:17 2007 +0200 +++ b/src/lib-storage/mail-storage.c Sat Nov 03 20:35:59 2007 +0200 @@ -529,6 +529,10 @@ struct mailbox_sync_context *ctx; struct mailbox_sync_rec sync_rec; + /* we don't care about mailbox's current state, so we might as well + fix inconsistency state */ + flags |= MAILBOX_SYNC_FLAG_FIX_INCONSISTENT; + ctx = mailbox_sync_init(box, flags); while (mailbox_sync_next(ctx, &sync_rec)) ;
--- a/src/lib-storage/mail-storage.h Sat Nov 03 20:22:17 2007 +0200 +++ b/src/lib-storage/mail-storage.h Sat Nov 03 20:35:59 2007 +0200 @@ -126,16 +126,18 @@ enum mailbox_sync_flags { /* Make sure we sync all external changes done to mailbox */ - MAILBOX_SYNC_FLAG_FULL_READ = 0x01, + MAILBOX_SYNC_FLAG_FULL_READ = 0x01, /* Make sure we write all our internal changes into the mailbox */ - MAILBOX_SYNC_FLAG_FULL_WRITE = 0x02, + MAILBOX_SYNC_FLAG_FULL_WRITE = 0x02, /* If it's not too much trouble, check if there are some changes */ - MAILBOX_SYNC_FLAG_FAST = 0x04, + MAILBOX_SYNC_FLAG_FAST = 0x04, /* Don't sync expunges from our view */ - MAILBOX_SYNC_FLAG_NO_EXPUNGES = 0x08, + MAILBOX_SYNC_FLAG_NO_EXPUNGES = 0x08, /* Stop auto syncing */ - MAILBOX_SYNC_AUTO_STOP = 0x20 + MAILBOX_SYNC_AUTO_STOP = 0x20, + /* If mailbox is currently inconsistent, fix it instead of failing. */ + MAILBOX_SYNC_FLAG_FIX_INCONSISTENT = 0x40 }; enum mailbox_sync_type {