dovecot: Added MAILBOX_SYNC_FLAG_FIX_INCONSISTENT flag. mailbox_...
dovecot at dovecot.org
dovecot at dovecot.org
Sat Nov 3 20:36:04 EET 2007
details: http://hg.dovecot.org/dovecot/rev/2637fb191e5e
changeset: 6674:2637fb191e5e
user: Timo Sirainen <tss at iki.fi>
date: Sat Nov 03 20:35:59 2007 +0200
description:
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.
diffstat:
3 files changed, 38 insertions(+), 11 deletions(-)
src/lib-storage/index/index-sync.c | 33 +++++++++++++++++++++++++++------
src/lib-storage/mail-storage.c | 4 ++++
src/lib-storage/mail-storage.h | 12 +++++++-----
diffs (95 lines):
diff -r c5e4a7b75586 -r 2637fb191e5e src/lib-storage/index/index-sync.c
--- 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 @@ index_mailbox_sync_init(struct mailbox *
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 @@ index_mailbox_sync_init(struct mailbox *
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) {
diff -r c5e4a7b75586 -r 2637fb191e5e src/lib-storage/mail-storage.c
--- 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 @@ int mailbox_sync(struct mailbox *box, en
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))
;
diff -r c5e4a7b75586 -r 2637fb191e5e src/lib-storage/mail-storage.h
--- 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_transaction_flags {
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 {
More information about the dovecot-cvs
mailing list