From: Timo Sirainen Date: Sun, 4 May 2008 16:19:23 +0000 (+0300) Subject: mbox_lazy_writes: If errors are noticed in mbox, write changes to fix them X-Git-Tag: 1.1.rc5~19 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b6d817f0effeff645aadc01fd468a7d4084ba1f2;p=thirdparty%2Fdovecot%2Fcore.git mbox_lazy_writes: If errors are noticed in mbox, write changes to fix them immediately to avoid constant errors in logs. --HG-- branch : HEAD --- diff --git a/src/lib-storage/index/mbox/mbox-sync-private.h b/src/lib-storage/index/mbox/mbox-sync-private.h index 8ed18fbc17..33f12d0792 100644 --- a/src/lib-storage/index/mbox/mbox-sync-private.h +++ b/src/lib-storage/index/mbox/mbox-sync-private.h @@ -143,6 +143,7 @@ struct mbox_sync_context { unsigned int moved_offsets:1; unsigned int ext_modified:1; unsigned int index_reset:1; + unsigned int errors:1; }; int mbox_sync(struct mbox_mailbox *mbox, enum mbox_sync_flags flags); diff --git a/src/lib-storage/index/mbox/mbox-sync.c b/src/lib-storage/index/mbox/mbox-sync.c index bad07d95b3..6605f027b4 100644 --- a/src/lib-storage/index/mbox/mbox-sync.c +++ b/src/lib-storage/index/mbox/mbox-sync.c @@ -68,6 +68,7 @@ void mbox_sync_set_critical(struct mbox_sync_context *sync_ctx, { va_list va; + sync_ctx->errors = TRUE; if (sync_ctx->ext_modified) { mail_storage_set_critical(&sync_ctx->mbox->storage->storage, "mbox file %s was modified while we were syncing, " @@ -1455,6 +1456,7 @@ static void mbox_sync_restart(struct mbox_sync_context *sync_ctx) sync_ctx->dest_first_mail = TRUE; sync_ctx->ext_modified = FALSE; + sync_ctx->errors = FALSE; } static int mbox_sync_do(struct mbox_sync_context *sync_ctx, @@ -1501,16 +1503,25 @@ static int mbox_sync_do(struct mbox_sync_context *sync_ctx, } mbox_sync_restart(sync_ctx); - for (i = 0; i < 3; i++) { + for (i = 0;;) { ret = mbox_sync_loop(sync_ctx, &mail_ctx, partial); - if (ret > 0) + if (ret > 0 && !sync_ctx->errors) break; if (ret < 0) return -1; - /* partial syncing didn't work, do it again. we get here - also if we ran out of UIDs. */ - i_assert(sync_ctx->mbox->mbox_sync_dirty); + /* a) partial sync didn't work + b) we ran out of UIDs + c) syncing had errors */ + if (sync_ctx->delay_writes && !sync_ctx->mbox->mbox_readonly && + (sync_ctx->errors || sync_ctx->renumber_uids)) { + /* fixing a broken mbox state, be sure to write + the changes. */ + sync_ctx->delay_writes = FALSE; + } + if (++i == 3) + break; + mbox_sync_restart(sync_ctx); partial = FALSE; }