[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync-rewrite.c, 1.36, 1.37 mbox-sync.c, 1.107, 1.108

cras at dovecot.org cras at dovecot.org
Thu Oct 21 23:33:46 EEST 2004


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

Modified Files:
	mbox-sync-rewrite.c mbox-sync.c 
Log Message:
rewrite fixes



Index: mbox-sync-rewrite.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.36
retrieving revision 1.37
diff -u -d -r1.36 -r1.37
--- mbox-sync-rewrite.c	14 Oct 2004 23:41:17 -0000	1.36
+++ mbox-sync-rewrite.c	21 Oct 2004 20:33:44 -0000	1.37
@@ -284,7 +284,7 @@
 				   struct mbox_sync_mail *mails,
 				   uint32_t seq, uint32_t idx, uint32_t padding,
 				   off_t move_diff, uoff_t expunged_space,
-				   uoff_t end_offset)
+				   uoff_t end_offset, int first_nonexpunged)
 {
 	struct mbox_sync_mail_context mail_ctx;
 	uint32_t old_prev_msg_uid;
@@ -328,10 +328,11 @@
 			str_append_c(mail_ctx.header, '\n');
 	}
 
-	if (sync_ctx->dest_first_mail && expunged_space > 0) {
+	if (first_nonexpunged && expunged_space > 0) {
 		/* move From-line (after parsing headers so we don't
 		   overwrite them) */
-		if (mbox_move(sync_ctx, 0, mails[idx].from_offset,
+		if (mbox_move(sync_ctx, mails[idx].from_offset - expunged_space,
+			      mails[idx].from_offset,
 			      mails[idx].offset - mails[idx].from_offset) < 0)
 			return -1;
 	}
@@ -390,7 +391,7 @@
 {
 	struct mbox_sync_mail *mails;
 	uoff_t offset, dest_offset, next_end_offset, next_move_diff;
-	uoff_t expunged_space;
+	uoff_t start_offset, expunged_space;
 	uint32_t idx, first_nonexpunged_idx, padding_per_mail;
 	size_t size;
 	int ret = 0;
@@ -411,6 +412,7 @@
 	/* after expunge the next mail must have been missing space, or we
 	   would have moved it backwards already */
 	expunged_space = 0;
+	start_offset = mails[0].from_offset;
 	for (first_nonexpunged_idx = 0;; first_nonexpunged_idx++) {
 		i_assert(first_nonexpunged_idx != idx);
 		if ((mails[first_nonexpunged_idx].flags & MBOX_EXPUNGED) == 0)
@@ -420,7 +422,8 @@
 	i_assert(mails[first_nonexpunged_idx].space < 0);
 
 	/* start moving backwards. */
-	while (idx-- > first_nonexpunged_idx) {
+	while (idx > first_nonexpunged_idx) {
+		idx--;
 		if (idx == first_nonexpunged_idx) {
 			/* give the rest of the extra space to first mail.
 			   we might also have to move the mail backwards to
@@ -430,21 +433,26 @@
 		}
 
 		next_end_offset = mails[idx].offset;
+
 		if (mails[idx].space <= 0 &&
 		    (mails[idx].flags & MBOX_EXPUNGED) == 0) {
-			/* give space to this mail */
+			/* give space to this mail. end_offset is left to
+			   contain this message's From-line (ie. below we
+			   move only headers + body). */
+			int first_nonexpunged = idx == first_nonexpunged_idx;
+
 			next_move_diff = -mails[idx].space;
 			if (mbox_sync_read_and_move(sync_ctx, mails,
 						    first_seq + idx, idx,
 						    padding_per_mail,
 						    move_diff, expunged_space,
-						    end_offset) < 0) {
+						    end_offset,
+						    first_nonexpunged) < 0) {
 				ret = -1;
 				break;
 			}
 			move_diff -= next_move_diff + mails[idx].space;
-			if (idx == first_nonexpunged_idx)
-				move_diff += expunged_space;
+			end_offset = next_end_offset;
 		} else {
 			/* this mail provides more space. just move it forward
 			   from the extra space offset and set end_offset to
@@ -468,22 +476,24 @@
 				move_diff -= padding_per_mail;
 				mails[idx].space = padding_per_mail;
 			}
-			if (mbox_fill_space(sync_ctx,
-					    mails[idx].offset + move_diff,
+
+			mails[idx].offset += move_diff;
+			if (mbox_fill_space(sync_ctx, mails[idx].offset,
 					    padding_per_mail) < 0) {
 				ret = -1;
 				break;
 			}
-			mails[idx].offset += move_diff;
 		}
 
 		i_assert(idx > 0 || move_diff == 0);
 
 		end_offset = next_end_offset;
 		mails[idx].from_offset += move_diff;
-		i_assert(move_diff < OFF_T_MAX);
 	}
 
+	i_assert(mails[idx].from_offset == start_offset);
+	i_assert(move_diff + (off_t)expunged_space >= 0);
+
 	istream_raw_mbox_flush(sync_ctx->input);
 	return ret;
 }

Index: mbox-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.107
retrieving revision 1.108
diff -u -d -r1.107 -r1.108
--- mbox-sync.c	14 Oct 2004 19:42:04 -0000	1.107
+++ mbox-sync.c	21 Oct 2004 20:33:44 -0000	1.108
@@ -584,7 +584,8 @@
 
 			memset(&mail, 0, sizeof(mail));
 			mail.flags = MBOX_EXPUNGED;
-			mail.offset = mail_ctx->mail.from_offset -
+			mail.offset = mail.from_offset =
+				mail_ctx->mail.from_offset -
 				sync_ctx->expunged_space;
 			mail.space = sync_ctx->expunged_space;
 



More information about the dovecot-cvs mailing list