dovecot-1.2: mbox: If we detect corrupted cached offsets/sizes, ...

dovecot at dovecot.org dovecot at dovecot.org
Sat Aug 30 14:56:45 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/8b0e3e27b551
changeset: 8127:8b0e3e27b551
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Aug 30 14:56:41 2008 +0300
description:
mbox: If we detect corrupted cached offsets/sizes, make sure the mbox gets resynced.

diffstat:

4 files changed, 31 insertions(+), 4 deletions(-)
src/lib-storage/index/mbox/istream-raw-mbox.c |    8 ++++++++
src/lib-storage/index/mbox/istream-raw-mbox.h |    2 ++
src/lib-storage/index/mbox/mbox-mail.c        |    8 +++++++-
src/lib-storage/index/mbox/mbox-storage.c     |   17 ++++++++++++++---

diffs (100 lines):

diff -r cf2c4f3c636f -r 8b0e3e27b551 src/lib-storage/index/mbox/istream-raw-mbox.c
--- a/src/lib-storage/index/mbox/istream-raw-mbox.c	Sat Aug 30 14:39:53 2008 +0300
+++ b/src/lib-storage/index/mbox/istream-raw-mbox.c	Sat Aug 30 14:56:41 2008 +0300
@@ -647,3 +647,11 @@ bool istream_raw_mbox_is_eof(struct istr
 
 	return rstream->eof;
 }
+
+bool istream_raw_mbox_is_corrupted(struct istream *stream)
+{
+	struct raw_mbox_istream *rstream =
+		(struct raw_mbox_istream *)stream->real_stream;
+
+	return rstream->corrupted;
+}
diff -r cf2c4f3c636f -r 8b0e3e27b551 src/lib-storage/index/mbox/istream-raw-mbox.h
--- a/src/lib-storage/index/mbox/istream-raw-mbox.h	Sat Aug 30 14:39:53 2008 +0300
+++ b/src/lib-storage/index/mbox/istream-raw-mbox.h	Sat Aug 30 14:56:41 2008 +0300
@@ -42,5 +42,7 @@ void istream_raw_mbox_set_next_offset(st
 
 /* Returns TRUE if we've read the whole mbox. */
 bool istream_raw_mbox_is_eof(struct istream *stream);
+/* Returns TRUE if we've noticed corruption in used offsets/sizes. */
+bool istream_raw_mbox_is_corrupted(struct istream *stream);
 
 #endif
diff -r cf2c4f3c636f -r 8b0e3e27b551 src/lib-storage/index/mbox/mbox-mail.c
--- a/src/lib-storage/index/mbox/mbox-mail.c	Sat Aug 30 14:39:53 2008 +0300
+++ b/src/lib-storage/index/mbox/mbox-mail.c	Sat Aug 30 14:56:41 2008 +0300
@@ -42,6 +42,12 @@ static int mbox_mail_seek(struct index_m
 	if (mail->mail.mail.expunged || mbox->syncing)
 		return -1;
 
+	if (mbox->mbox_stream != NULL &&
+	    istream_raw_mbox_is_corrupted(mbox->mbox_stream)) {
+		/* clear the corruption by forcing a full resync */
+		sync_flags |= MBOX_SYNC_UNDIRTY | MBOX_SYNC_FORCE_SYNC;
+	}
+
 	for (try = 0; try < 2; try++) {
 		if (mbox->mbox_lock_type == F_UNLCK) {
 			sync_flags |= MBOX_SYNC_LOCK_READING;
@@ -60,6 +66,7 @@ static int mbox_mail_seek(struct index_m
 		} else if ((sync_flags & MBOX_SYNC_FORCE_SYNC) != 0) {
 			/* dirty offsets are broken and mbox is write-locked.
 			   sync it to update offsets. */
+			mbox_prepare_resync(mail);
 			if (mbox_sync(mbox, sync_flags) < 0)
 				return -1;
 		}
@@ -80,7 +87,6 @@ static int mbox_mail_seek(struct index_m
 		}
 
 		/* we'll need to re-sync it completely */
-		mbox_prepare_resync(mail);
 		sync_flags |= MBOX_SYNC_UNDIRTY | MBOX_SYNC_FORCE_SYNC;
 	}
 	if (ret == 0) {
diff -r cf2c4f3c636f -r 8b0e3e27b551 src/lib-storage/index/mbox/mbox-storage.c
--- a/src/lib-storage/index/mbox/mbox-storage.c	Sat Aug 30 14:39:53 2008 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Sat Aug 30 14:56:41 2008 +0300
@@ -12,6 +12,7 @@
 #include "mbox-lock.h"
 #include "mbox-file.h"
 #include "mbox-sync-private.h"
+#include "istream-raw-mbox.h"
 #include "mail-copy.h"
 #include "index-mail.h"
 
@@ -762,7 +763,14 @@ static int mbox_storage_mailbox_close(st
 {
 	struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
 	const struct mail_index_header *hdr;
+	enum mbox_sync_flags sync_flags = 0;
 	int ret = 0;
+
+	if (mbox->mbox_stream != NULL &&
+	    istream_raw_mbox_is_corrupted(mbox->mbox_stream)) {
+		/* clear the corruption by forcing a full resync */
+		sync_flags |= MBOX_SYNC_UNDIRTY | MBOX_SYNC_FORCE_SYNC;
+	}
 
 	if (mbox->ibox.view != NULL) {
 		hdr = mail_index_get_header(mbox->ibox.view);
@@ -770,9 +778,12 @@ static int mbox_storage_mailbox_close(st
 		    !mbox->mbox_readonly) {
 			/* we've done changes to mbox which haven't been
 			   written yet. do it now. */
-			if (mbox_sync(mbox, MBOX_SYNC_REWRITE) < 0)
-				ret = -1;
-		}
+			sync_flags |= MBOX_SYNC_REWRITE;
+		}
+	}
+	if (sync_flags != 0) {
+		if (mbox_sync(mbox, sync_flags) < 0)
+			ret = -1;
 	}
 
 	if (mbox->mbox_global_lock_id != 0)


More information about the dovecot-cvs mailing list