changeset 7483:591145eaaf87 HEAD

mbox_lazy_writes: If errors are noticed in mbox, write changes to fix them immediately to avoid constant errors in logs.
author Timo Sirainen <tss@iki.fi>
date Sun, 04 May 2008 19:19:23 +0300
parents 955ae7b7ad1a
children 96f724a4a1a0
files src/lib-storage/index/mbox/mbox-sync-private.h src/lib-storage/index/mbox/mbox-sync.c
diffstat 2 files changed, 17 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-sync-private.h	Sun May 04 18:19:57 2008 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-private.h	Sun May 04 19:19:23 2008 +0300
@@ -143,6 +143,7 @@
 	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);
--- a/src/lib-storage/index/mbox/mbox-sync.c	Sun May 04 18:19:57 2008 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Sun May 04 19:19:23 2008 +0300
@@ -68,6 +68,7 @@
 {
 	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 @@
 
 	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 @@
 	}
 
 	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;
 	}