[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync-parse.c, 1.26, 1.27 mbox-sync-private.h, 1.31, 1.32 mbox-sync.c, 1.86, 1.87

cras at dovecot.org cras at dovecot.org
Thu Sep 23 13:41:40 EEST 2004


Update of /var/lib/cvs/dovecot/src/lib-storage/index/mbox
In directory talvi:/tmp/cvs-serv8459

Modified Files:
	mbox-sync-parse.c mbox-sync-private.h mbox-sync.c 
Log Message:
Handle UIDVALIDITY changes. When partial syncing, make sure UIDs of new
mails are larger than existing ones. If partial syncing fails, we need to
rollback the transaction.



Index: mbox-sync-parse.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-parse.c,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- mbox-sync-parse.c	20 Sep 2004 20:45:58 -0000	1.26
+++ mbox-sync-parse.c	23 Sep 2004 10:41:38 -0000	1.27
@@ -215,6 +215,7 @@
 
 		if (value <= ctx->sync_ctx->prev_msg_uid) {
 			/* broken - UIDs must be growing */
+			ctx->uid_broken = TRUE;
 			return FALSE;
 		}
 		ctx->sync_ctx->prev_msg_uid = value;

Index: mbox-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.31
retrieving revision 1.32
diff -u -d -r1.31 -r1.32
--- mbox-sync-private.h	11 Sep 2004 18:30:50 -0000	1.31
+++ mbox-sync-private.h	23 Sep 2004 10:41:38 -0000	1.32
@@ -82,6 +82,7 @@
 	unsigned int updated:1;
 	unsigned int recent:1;
 	unsigned int seen_received_hdr:1;
+	unsigned int uid_broken:1;
 };
 
 struct mbox_sync_context {

Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.86
retrieving revision 1.87
diff -u -d -r1.86 -r1.87
--- mbox-sync.c	23 Sep 2004 09:40:48 -0000	1.86
+++ mbox-sync.c	23 Sep 2004 10:41:38 -0000	1.87
@@ -616,6 +616,7 @@
 {
 	struct index_mailbox *ibox = sync_ctx->ibox;
 	uoff_t old_offset;
+	uint32_t uid;
 	int ret, deleted;
 
 	if (seq == 0) {
@@ -647,6 +648,15 @@
 		}
 	}
 
+	if (seq <= 1)
+		uid = 0;
+	else if (mail_index_lookup_uid(sync_ctx->sync_view, seq-1, &uid) < 0) {
+		mail_storage_set_index_error(ibox);
+		return -1;
+	}
+
+	sync_ctx->prev_msg_uid = uid;
+
         /* set to -1, since it's always increased later */
 	sync_ctx->seq = seq-1;
 	if (sync_ctx->seq == 0 &&
@@ -722,6 +732,26 @@
 	while ((ret = mbox_sync_read_next_mail(sync_ctx, mail_ctx)) > 0) {
 		uid = mail_ctx->mail.uid;
 
+		if (mail_ctx->seq == 1 && sync_ctx->base_uid_validity != 0 &&
+                    sync_ctx->hdr->uid_validity != 0 &&
+		    sync_ctx->base_uid_validity !=
+		    sync_ctx->hdr->uid_validity) {
+			mail_storage_set_critical(sync_ctx->ibox->box.storage,
+				"UIDVALIDITY changed (%u -> %u) "
+				"in mbox file %s",
+				sync_ctx->hdr->uid_validity,
+				sync_ctx->base_uid_validity,
+				sync_ctx->ibox->path);
+                        mail_index_mark_corrupted(sync_ctx->ibox->index);
+			return -1;
+		}
+
+		if (mail_ctx->uid_broken && partial) {
+			/* UID ordering problems, resync everything to make
+			   sure we get everything right */
+			return 0;
+		}
+
 		if (mail_ctx->pseudo)
 			uid = 0;
 
@@ -1033,9 +1063,16 @@
 
 		/* partial syncing didn't work, do it again */
 		mbox_sync_restart(sync_ctx);
-		if (mbox_sync_loop(sync_ctx, &mail_ctx,
-				   (uint32_t)-1, FALSE) < 0)
+
+		mail_index_transaction_rollback(sync_ctx->t);
+		sync_ctx->t = mail_index_transaction_begin(sync_ctx->sync_view,
+							   FALSE);
+
+		ret = mbox_sync_loop(sync_ctx, &mail_ctx, (uint32_t)-1, FALSE);
+		if (ret <= 0) {
+			i_assert(ret != 0);
 			return -1;
+		}
 	}
 
 	if (mbox_sync_handle_eof_updates(sync_ctx, &mail_ctx) < 0)



More information about the dovecot-cvs mailing list