[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync-private.h, 1.56.2.2, 1.56.2.3 mbox-sync-rewrite.c, 1.62.2.4, 1.62.2.5 mbox-sync-update.c, 1.46.2.1, 1.46.2.2 mbox-sync.c, 1.181.2.8, 1.181.2.9

tss at dovecot.org tss at dovecot.org
Mon Jan 22 12:44:14 UTC 2007


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

Modified Files:
      Tag: branch_1_0
	mbox-sync-private.h mbox-sync-rewrite.c mbox-sync-update.c 
	mbox-sync.c 
Log Message:
Restore sync_ctx->next_uid to original value when beginning a rewrite. This
could fix some problems with broken UIDs causing crashes.



Index: mbox-sync-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.56.2.2
retrieving revision 1.56.2.3
diff -u -d -r1.56.2.2 -r1.56.2.3
--- mbox-sync-private.h	26 Oct 2006 00:17:22 -0000	1.56.2.2
+++ mbox-sync-private.h	22 Jan 2007 12:44:11 -0000	1.56.2.3
@@ -121,6 +121,7 @@
 	pool_t saved_keywords_pool;
 
 	uint32_t prev_msg_uid, next_uid, idx_next_uid;
+	uint32_t prev_next_uid, need_space_next_uid;
 	uint32_t seq, idx_seq, need_space_seq;
 	off_t expunged_space, space_diff;
 

Index: mbox-sync-rewrite.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.62.2.4
retrieving revision 1.62.2.5
diff -u -d -r1.62.2.4 -r1.62.2.5
--- mbox-sync-rewrite.c	15 Oct 2006 22:47:48 -0000	1.62.2.4
+++ mbox-sync-rewrite.c	22 Jan 2007 12:44:11 -0000	1.62.2.5
@@ -319,7 +319,6 @@
 				uint32_t seq, uint32_t idx,
 				uoff_t expunged_space)
 {
-	uint32_t old_prev_msg_uid;
 	unsigned int first_mail_expunge_extra;
 
 	memset(mail_ctx, 0, sizeof(*mail_ctx));
@@ -333,7 +332,6 @@
 
 	/* mbox_sync_parse_next_mail() checks that UIDs are growing,
 	   so we have to fool it. */
-	old_prev_msg_uid = sync_ctx->prev_msg_uid;
 	sync_ctx->prev_msg_uid = mails[idx].uid == 0 ? 0 : mails[idx].uid-1;
 
 	first_mail_expunge_extra = 1 +
@@ -362,7 +360,8 @@
 			str_append_c(mail_ctx->header, '\n');
 	}
 
-	sync_ctx->prev_msg_uid = old_prev_msg_uid;
+	if (mail_ctx->mail.uid >= sync_ctx->next_uid)
+		sync_ctx->next_uid = mail_ctx->mail.uid + 1;
 }
 
 static int mbox_sync_read_and_move(struct mbox_sync_context *sync_ctx,
@@ -454,6 +453,7 @@
 	uoff_t offset, dest_offset, next_end_offset, next_move_diff;
 	uoff_t start_offset, expunged_space;
 	uint32_t idx, first_nonexpunged_idx, padding_per_mail;
+	uint32_t orig_prev_msg_uid, orig_next_uid;
 	unsigned int count;
 	int ret = 0;
 
@@ -483,6 +483,11 @@
 	}
 	i_assert(mails[first_nonexpunged_idx].space < 0);
 
+	/* broken UIDs are generated from next_uid */
+	orig_prev_msg_uid = sync_ctx->prev_msg_uid;
+	orig_next_uid = sync_ctx->next_uid;
+	sync_ctx->next_uid = sync_ctx->need_space_next_uid;
+
 	/* start moving backwards. */
 	while (idx > first_nonexpunged_idx) {
 		idx--;
@@ -559,5 +564,8 @@
 	i_assert(move_diff + (off_t)expunged_space >= 0);
 
 	i_stream_sync(sync_ctx->input);
+	sync_ctx->next_uid = orig_next_uid;
+	sync_ctx->need_space_next_uid = 0;
+	sync_ctx->prev_msg_uid = orig_prev_msg_uid;
 	return ret;
 }

Index: mbox-sync-update.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-update.c,v
retrieving revision 1.46.2.1
retrieving revision 1.46.2.2
diff -u -d -r1.46.2.1 -r1.46.2.2
--- mbox-sync-update.c	24 Jun 2006 20:53:36 -0000	1.46.2.1
+++ mbox-sync-update.c	22 Jan 2007 12:44:11 -0000	1.46.2.2
@@ -453,11 +453,7 @@
 		mbox_sync_update_xkeywords(ctx);
 	}
 
-	/* we might not have done the UID validity checks in same way this
-	   time, so just overwrite conflicting UIDs if uid_broken was set in
-	   first parse time */
-	i_assert(ctx->mail.uid == 0 || ctx->mail.uid_broken ||
-		 ctx->mail.uid == mail->uid);
+	i_assert(ctx->mail.uid == 0 || ctx->mail.uid == mail->uid);
 	ctx->mail.uid = mail->uid;
 
 	mbox_sync_update_x_imap_base(ctx);

Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.181.2.8
retrieving revision 1.181.2.9
diff -u -d -r1.181.2.8 -r1.181.2.9
--- mbox-sync.c	22 Jan 2007 12:11:08 -0000	1.181.2.8
+++ mbox-sync.c	22 Jan 2007 12:44:11 -0000	1.181.2.9
@@ -115,6 +115,7 @@
 		istream_raw_mbox_get_start_offset(sync_ctx->input);
 	mail_ctx->mail.offset =
 		istream_raw_mbox_get_header_offset(sync_ctx->input);
+	sync_ctx->prev_next_uid = sync_ctx->next_uid;
 
 	mbox_sync_parse_next_mail(sync_ctx->input, mail_ctx);
 	i_assert(sync_ctx->input->v_offset != mail_ctx->mail.from_offset ||
@@ -760,6 +761,10 @@
 		sync_ctx->need_space_seq = sync_ctx->seq;
 		sync_ctx->space_diff = 0;
 
+		/* remember what the next_uid was before we parsed this mail,
+		   so that rewriting can set it back */
+		sync_ctx->need_space_next_uid = sync_ctx->prev_next_uid;
+
 		if (sync_ctx->expunged_space > 0) {
 			/* create dummy message to describe the expunged data */
 			struct mbox_sync_mail mail;



More information about the dovecot-cvs mailing list