changeset 2034:8078400fe561 HEAD

Fix bogus "UID inserted in the middle of mailbox" errors
author Timo Sirainen <tss@iki.fi>
date Sat, 22 May 2004 04:18:17 +0300
parents 4f6b1118a53d
children 0e65efd14eda
files src/lib-storage/index/maildir/maildir-sync.c
diffstat 1 files changed, 30 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-sync.c	Sat May 22 03:48:45 2004 +0300
+++ b/src/lib-storage/index/maildir/maildir-sync.c	Sat May 22 04:18:17 2004 +0300
@@ -602,15 +602,36 @@
 		}
 
 		if (rec->uid > uid) {
-			/* new UID in the middle of the mailbox -
-			   shouldn't happen */
-			mail_storage_set_critical(ibox->box.storage,
-				"Maildir sync: UID inserted in the middle "
-				"of mailbox (%u > %u, file = %s)",
-				rec->uid, uid, filename);
-			mail_index_mark_corrupted(ibox->index);
-			ret = -1;
-			break;
+			/* most likely a race condition: we read the
+			   maildir, then someone else expunged messages and
+			   committed changes to index. so, this message
+			   shouldn't actually exist. check to be sure.
+
+			   FIXME: we could avoid this stat() and just mark
+			   this check in the uidlist and check it at next
+			   sync.. */
+			struct stat st;
+			const char *str;
+
+			t_push();
+			str = t_strdup_printf("%s/%s",
+				(uflags & MAILDIR_UIDLIST_REC_FLAG_NEW_DIR) ?
+				ctx->new_dir : ctx->cur_dir, filename);
+			if (stat(str, &st) == 0) {
+				t_pop();
+				mail_storage_set_critical(ibox->box.storage,
+					"Maildir sync: UID inserted in the "
+					"middle of mailbox "
+					"(%u > %u, file = %s)",
+					rec->uid, uid, filename);
+				mail_index_mark_corrupted(ibox->index);
+				ret = -1;
+				break;
+			}
+			t_pop();
+
+			seq--;
+			continue;
 		}
 
 		if ((rec->flags & MAIL_INDEX_MAIL_FLAG_DIRTY) != 0) {