[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync-parse.c, 1.8, 1.9 mbox-sync-private.h, 1.7, 1.8 mbox-sync-rewrite.c, 1.7, 1.8 mbox-sync-update.c, 1.6, 1.7 mbox-sync.c, 1.13, 1.14

cras at procontrol.fi cras at procontrol.fi
Sun Jun 13 10:12:26 EEST 2004


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

Modified Files:
	mbox-sync-parse.c mbox-sync-private.h mbox-sync-rewrite.c 
	mbox-sync-update.c mbox-sync.c 
Log Message:
some more fixes



Index: mbox-sync-parse.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-parse.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mbox-sync-parse.c	3 Jun 2004 15:01:27 -0000	1.8
+++ mbox-sync-parse.c	13 Jun 2004 07:12:24 -0000	1.9
@@ -304,7 +304,8 @@
 	}
 	message_parse_header_deinit(hdr_ctx);
 
-	if (ctx->seq == 1 && ctx->sync_ctx->base_uid_validity == 0) {
+	if ((ctx->seq == 1 && ctx->sync_ctx->base_uid_validity == 0) ||
+	    (ctx->seq > 1 && ctx->sync_ctx->first_uid == 0)) {
 		/* missing X-IMAPbase */
 		ctx->need_rewrite = TRUE;
 	}

Index: mbox-sync-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mbox-sync-private.h	11 Jun 2004 03:20:10 -0000	1.7
+++ mbox-sync-private.h	13 Jun 2004 07:12:24 -0000	1.8
@@ -52,6 +52,7 @@
 	unsigned int have_eoh:1;
 	unsigned int need_rewrite:1;
 	unsigned int seen_imapbase:1;
+	unsigned int updated:1;
 };
 
 struct mbox_sync_context {
@@ -61,7 +62,7 @@
 
 	string_t *header, *from_line;
 	uint32_t base_uid_validity, base_uid_last;
-	uint32_t prev_msg_uid, next_uid;
+	uint32_t prev_msg_uid, next_uid, first_uid;
 	off_t expunged_space;
 };
 

Index: mbox-sync-rewrite.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- mbox-sync-rewrite.c	13 Jun 2004 06:03:29 -0000	1.7
+++ mbox-sync-rewrite.c	13 Jun 2004 07:12:24 -0000	1.8
@@ -242,7 +242,8 @@
 			str_append_c(mail_ctx.header, '\n');
 	}
 
-	i_assert(mail_ctx.mail.space == mails[idx].space);
+	/* breaks with leftover space:
+	   i_assert(mail_ctx.mail.space == mails[idx].space);*/
         sync_ctx->prev_msg_uid = old_prev_msg_uid;
 
 	/* we're moving next message - update it's from_offset */
@@ -285,7 +286,7 @@
 		      uint32_t first_seq, uint32_t last_seq, off_t extra_space)
 {
 	/* FIXME: with mails[0] = expunged and first_seq=1, we leave the
-	   \n header? */
+	   \n header! */
 	struct mbox_sync_mail *mails;
 	size_t size;
 	uoff_t offset, start_offset, end_offset, dest_offset;
@@ -303,7 +304,7 @@
 	   data which hasn't yet been copied backwards. to avoid too much
 	   complexity, we just leave all the rest of the extra space to first
 	   mail */
-	extra_per_mail = extra_space / (last_seq - first_seq + 1+3);
+	extra_per_mail = extra_space / (last_seq - first_seq + 1);
 	idx = last_seq - first_seq;
 
 	if (mails[idx].uid != 0)

Index: mbox-sync-update.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-update.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -d -r1.6 -r1.7
--- mbox-sync-update.c	11 Jun 2004 03:20:10 -0000	1.6
+++ mbox-sync-update.c	13 Jun 2004 07:12:24 -0000	1.7
@@ -87,7 +87,8 @@
 	old_hdr_size = ctx->body_offset - ctx->hdr_offset;
 	new_hdr_size = str_len(ctx->header);
 
-	if (ctx->seq == 1 && ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] == (size_t)-1) {
+	if (ctx->mail.uid == ctx->sync_ctx->first_uid &&
+	    ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] == (size_t)-1) {
 		ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] = str_len(ctx->header);
 		str_printfa(ctx->header, "X-IMAPbase: %u %u",
 			    ctx->sync_ctx->base_uid_validity,
@@ -216,7 +217,8 @@
 		}
 	}
 
-        mbox_sync_add_missing_headers(ctx);
+	mbox_sync_add_missing_headers(ctx);
+	ctx->updated = TRUE;
 }
 
 void mbox_sync_update_header_from(struct mbox_sync_mail_context *ctx,

Index: mbox-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- mbox-sync.c	13 Jun 2004 06:03:29 -0000	1.13
+++ mbox-sync.c	13 Jun 2004 07:12:24 -0000	1.14
@@ -206,11 +206,11 @@
 
 static int mbox_sync_do(struct index_mailbox *ibox,
 			struct mail_index_sync_ctx *index_sync_ctx,
-			struct mail_index_view *sync_view)
+			struct mail_index_view *sync_view,
+			buffer_t *syncs, struct mail_index_sync_rec *sync_rec)
 {
 	struct mbox_sync_context sync_ctx;
 	struct mbox_sync_mail_context mail_ctx;
-	struct mail_index_sync_rec sync_rec;
 	struct mail_index_transaction *t;
 	const struct mail_index_header *hdr;
 	const struct mail_index_record *rec;
@@ -219,7 +219,7 @@
 	uint8_t new_flags;
 	off_t space_diff, move_diff;
 	uoff_t offset, extra_space, trailer_size;
-	buffer_t *mails, *syncs;
+	buffer_t *mails;
 	size_t size;
 	struct stat st;
 	int sync_expunge, ret = 0;
@@ -246,9 +246,7 @@
 	istream_raw_mbox_seek(input, 0);
 
 	mails = buffer_create_dynamic(default_pool, 4096, (size_t)-1);
-	syncs = buffer_create_dynamic(default_pool, 256, (size_t)-1);
 
-	memset(&sync_rec, 0, sizeof(sync_rec));
 	messages_count = mail_index_view_get_message_count(sync_view);
 
 	space_diff = 0; need_space_seq = 0; idx_seq = 0; rec = NULL;
@@ -264,19 +262,19 @@
 		/* get all sync records related to this message */
 		ret = 1; sync_expunge = FALSE;
 		mbox_sync_buffer_delete_old(syncs, mail_ctx.mail.uid);
-		while (mail_ctx.mail.uid >= sync_rec.uid1 && ret > 0) {
-			if (sync_rec.uid1 != 0) {
-				i_assert(mail_ctx.mail.uid <= sync_rec.uid2);
-				buffer_append(syncs, &sync_rec,
-					      sizeof(sync_rec));
+		while (mail_ctx.mail.uid >= sync_rec->uid1 && ret > 0) {
+			if (sync_rec->uid1 != 0) {
+				i_assert(mail_ctx.mail.uid <= sync_rec->uid2);
+				buffer_append(syncs, sync_rec,
+					      sizeof(*sync_rec));
 
-				if (sync_rec.type ==
+				if (sync_rec->type ==
 				    MAIL_INDEX_SYNC_TYPE_EXPUNGE)
 					sync_expunge = TRUE;
 			}
-			ret = mail_index_sync_next(index_sync_ctx, &sync_rec);
+			ret = mail_index_sync_next(index_sync_ctx, sync_rec);
 			if (ret == 0)
-				memset(&sync_rec, 0, sizeof(sync_rec));
+				memset(sync_rec, 0, sizeof(*sync_rec));
 		}
 		if (ret < 0)
 			break;
@@ -291,6 +289,9 @@
 				hdr->uid_validity;
 		}
 
+		if (!sync_expunge && sync_ctx.first_uid == 0)
+			sync_ctx.first_uid = mail_ctx.mail.uid;
+
 		if ((mail_ctx.need_rewrite || sync_ctx.expunged_space > 0 ||
 		     buffer_get_used_size(syncs) != 0) && !ibox->readonly) {
 			if (ibox->mbox_lock_type == F_RDLCK) {
@@ -493,6 +494,9 @@
 		space_diff += sync_ctx.expunged_space;
 		sync_ctx.expunged_space -= -space_diff;
 
+		if (mail_ctx.have_eoh && !mail_ctx.updated)
+			str_append_c(mail_ctx.header, '\n');
+
 		if (space_diff < 0 &&
 		    mbox_sync_grow_file(&sync_ctx, &mail_ctx, -space_diff) < 0)
 			ret = -1;
@@ -541,7 +545,7 @@
 		/* only syncs left should be just appends (and their updates)
 		   which weren't synced yet for some reason (crash). we'll just
 		   ignore them, as we've overwritten them above. */
-		while (mail_index_sync_next(index_sync_ctx, &sync_rec) > 0)
+		while (mail_index_sync_next(index_sync_ctx, sync_rec) > 0)
 			;
 	}
 
@@ -615,7 +619,6 @@
 	str_free(sync_ctx.header);
 	str_free(sync_ctx.from_line);
 	buffer_free(mails);
-	buffer_free(syncs);
 	return ret < 0 ? ret : 0;
 }
 
@@ -626,6 +629,8 @@
 	unsigned int lock_id;
 	uint32_t seq;
 	uoff_t offset;
+	struct mail_index_sync_rec sync_rec;
+	buffer_t *syncs;
 	int ret, lock_type;
 
 	if (last_commit) {
@@ -641,11 +646,15 @@
 	if (ret <= 0)
 		return ret;
 
+	memset(&sync_rec, 0, sizeof(sync_rec));
+	syncs = buffer_create_dynamic(default_pool, 256, (size_t)-1);
+
 	lock_type = mail_index_sync_have_more(index_sync_ctx) ?
 		F_WRLCK : F_RDLCK;
 	if (mbox_lock(ibox, lock_type, &lock_id) > 0 &&
 	    mbox_file_open_stream(ibox) == 0) {
-		ret = mbox_sync_do(ibox, index_sync_ctx, sync_view);
+		ret = mbox_sync_do(ibox, index_sync_ctx, sync_view,
+				   syncs, &sync_rec);
 		if (ret == -2) {
 			/* read lock -> write lock. do it again. */
 			(void)mbox_unlock(ibox, lock_id);
@@ -656,7 +665,7 @@
 				ret = -1;
 			else {
 				ret = mbox_sync_do(ibox, index_sync_ctx,
-						   sync_view);
+						   sync_view, syncs, &sync_rec);
 			}
 		}
 	} else {
@@ -669,6 +678,7 @@
 			ret = -1;
 	}
 
+	buffer_free(syncs);
 	return ret;
 }
 



More information about the dovecot-cvs mailing list