[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync-private.h, 1.9, 1.10 mbox-sync-rewrite.c, 1.11, 1.12 mbox-sync-update.c, 1.8, 1.9 mbox-sync.c, 1.18, 1.19

cras at procontrol.fi cras at procontrol.fi
Mon Jun 14 22:23:27 EEST 2004


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

Modified Files:
	mbox-sync-private.h mbox-sync-rewrite.c mbox-sync-update.c 
	mbox-sync.c 
Log Message:
major syncing code cleanups. the code finally looks almost readable. logic
should have stayed same.



Index: mbox-sync-private.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-private.h,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -d -r1.9 -r1.10
--- mbox-sync-private.h	14 Jun 2004 04:30:32 -0000	1.9
+++ mbox-sync-private.h	14 Jun 2004 19:23:25 -0000	1.10
@@ -60,12 +60,24 @@
 struct mbox_sync_context {
 	struct index_mailbox *ibox;
 	struct istream *input, *file_input;
+	unsigned int lock_id;
 	int fd;
 
+	struct mail_index_sync_ctx *index_sync_ctx;
+	struct mail_index_view *sync_view;
+	struct mail_index_transaction *t;
+	const struct mail_index_header *hdr;
+
 	string_t *header, *from_line;
 	uint32_t base_uid_validity, base_uid_last;
+
+	/* state: */
+	buffer_t *mails, *syncs;
+	struct mail_index_sync_rec sync_rec;
+
 	uint32_t prev_msg_uid, next_uid, first_uid;
-	off_t expunged_space;
+	uint32_t seq, idx_seq, need_space_seq;
+	off_t expunged_space, space_diff;
 };
 
 int mbox_sync(struct index_mailbox *ibox, int last_commit);
@@ -77,7 +89,7 @@
 void mbox_sync_update_header_from(struct mbox_sync_mail_context *ctx,
 				  const struct mbox_sync_mail *mail);
 int mbox_sync_try_rewrite(struct mbox_sync_mail_context *ctx, off_t move_diff);
-int mbox_sync_rewrite(struct mbox_sync_context *sync_ctx, buffer_t *mails_buf,
+int mbox_sync_rewrite(struct mbox_sync_context *sync_ctx,
 		      uint32_t first_seq, uint32_t last_seq, off_t extra_space);
 
 int mbox_move(struct mbox_sync_context *sync_ctx,

Index: mbox-sync-rewrite.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-rewrite.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- mbox-sync-rewrite.c	14 Jun 2004 04:54:05 -0000	1.11
+++ mbox-sync-rewrite.c	14 Jun 2004 19:23:25 -0000	1.12
@@ -37,6 +37,12 @@
 		ret = ret == (off_t)size ? 0 : -1;
 	}
 
+	if (ret < 0) {
+		errno = output->stream_errno;
+		mbox_set_syscall_error(sync_ctx->ibox,
+				       "o_stream_send_istream()");
+	}
+
 	o_stream_unref(output);
 	return (int)ret;
 }
@@ -189,7 +195,7 @@
 			new_hdr_size - ctx->header_first_change,
 			ctx->hdr_offset + move_diff +
 			ctx->header_first_change) < 0) {
-		// FIXME: error handling
+		mbox_set_syscall_error(ctx->sync_ctx->ibox, "pwrite_full()");
 		return -1;
 	}
 	istream_raw_mbox_flush(ctx->sync_ctx->input);
@@ -249,17 +255,15 @@
 	   headers. */
 	offset = sync_ctx->file_input->v_offset;
 	if (mbox_move(sync_ctx, offset + mails[idx+1].space, offset,
-		      *end_offset - offset - mails[idx+1].space) < 0) {
-		// FIXME: error handling
+		      *end_offset - offset - mails[idx+1].space) < 0)
 		return -1;
-	}
 	mails[idx+1].from_offset += mails[idx+1].space;
 
 	*end_offset = offset + mails[idx+1].space - str_len(mail_ctx.header);
 
 	if (pwrite_full(sync_ctx->fd, str_data(mail_ctx.header),
 			str_len(mail_ctx.header), *end_offset) < 0) {
-		// FIXME: error handling
+		mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()");
 		return -1;
 	}
 
@@ -300,7 +304,7 @@
 
 	if (pwrite_full(sync_ctx->fd, str_data(mail_ctx.header),
 			str_len(mail_ctx.header), start_offset) < 0) {
-		// FIXME: error handling
+		mbox_set_syscall_error(sync_ctx->ibox, "pwrite_full()");
 		return -1;
 	}
 
@@ -308,7 +312,7 @@
 	return 0;
 }
 
-int mbox_sync_rewrite(struct mbox_sync_context *sync_ctx, buffer_t *mails_buf,
+int mbox_sync_rewrite(struct mbox_sync_context *sync_ctx,
 		      uint32_t first_seq, uint32_t last_seq, off_t extra_space)
 {
 	struct mbox_sync_mail *mails;
@@ -320,7 +324,7 @@
 	i_assert(first_seq != last_seq);
 	i_assert(sync_ctx->ibox->mbox_lock_type == F_WRLCK);
 
-	mails = buffer_get_modifyable_data(mails_buf, &size);
+	mails = buffer_get_modifyable_data(sync_ctx->mails, &size);
 	i_assert(size / sizeof(*mails) == last_seq - first_seq + 1);
 
 	/* if there's expunges in mails[], we would get more correct balancing
@@ -368,7 +372,6 @@
 			dest_offset = offset + mails[idx+1].space;
 			if (mbox_move(sync_ctx, dest_offset, offset,
 				      end_offset - dest_offset) < 0) {
-				// FIXME: error handling
 				ret = -1;
 				break;
 			}
@@ -390,10 +393,8 @@
 			   we need to move From-line to start_offset */
 			offset = mails[1].offset;
 			if (mbox_move(sync_ctx, start_offset, end_offset,
-				      offset - end_offset) < 0) {
-				// FIXME: error handling
+				      offset - end_offset) < 0)
 				ret = -1;
-			}
 			mails[1].from_offset -= end_offset - start_offset;
 			idx++;
 

Index: mbox-sync-update.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync-update.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- mbox-sync-update.c	14 Jun 2004 04:30:32 -0000	1.8
+++ mbox-sync-update.c	14 Jun 2004 19:23:25 -0000	1.9
@@ -1,4 +1,5 @@
 #include "lib.h"
+#include "ioloop.h"
 #include "buffer.h"
 #include "str.h"
 #include "message-parser.h"
@@ -89,6 +90,13 @@
 
 	if (ctx->mail.uid == ctx->sync_ctx->first_uid &&
 	    ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] == (size_t)-1) {
+		if (ctx->sync_ctx->base_uid_validity == 0) {
+			ctx->sync_ctx->base_uid_validity =
+				ctx->sync_ctx->hdr->uid_validity == 0 ?
+				(uint32_t)ioloop_time :
+				ctx->sync_ctx->hdr->uid_validity;
+		}
+
 		ctx->hdr_pos[MBOX_HDR_X_IMAPBASE] = str_len(ctx->header);
 		str_printfa(ctx->header, "X-IMAPbase: %u %010u",
 			    ctx->sync_ctx->base_uid_validity,
@@ -197,6 +205,9 @@
 		memcpy(old_keywords, ctx->mail.keywords, sizeof(old_keywords));
 
 		for (i = 0; i < size; i++) {
+			if (sync[i].type != MAIL_INDEX_SYNC_TYPE_FLAGS)
+				continue;
+
 			mail_index_sync_flags_apply(&sync[i], &ctx->mail.flags,
 						    ctx->mail.keywords);
 		}

Index: mbox-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -d -r1.18 -r1.19
--- mbox-sync.c	14 Jun 2004 04:54:05 -0000	1.18
+++ mbox-sync.c	14 Jun 2004 19:23:25 -0000	1.19
@@ -70,8 +70,10 @@
 
 	/* put the extra space between last message's header and body */
 	file_size = i_stream_get_size(sync_ctx->file_input) + grow_size;
-	if (file_set_size(sync_ctx->fd, file_size) < 0)
+	if (file_set_size(sync_ctx->fd, file_size) < 0) {
+		mbox_set_syscall_error(sync_ctx->ibox, "file_set_size()");
 		return -1;
+	}
 
 	src_offset = mail_ctx->body_offset;
 	mail_ctx->body_offset += grow_size;
[...1015 lines suppressed...]
 	}
 
-	if (lock_id != 0) {
-		if (mbox_unlock(ibox, lock_id) < 0)
+	if (mail_index_sync_end(index_sync_ctx) < 0)
+		ret = -1;
+
+	if (sync_ctx.lock_id != 0) {
+		if (mbox_unlock(ibox, sync_ctx.lock_id) < 0)
 			ret = -1;
 	}
 
-	buffer_free(syncs);
+	str_free(sync_ctx.header);
+	str_free(sync_ctx.from_line);
+	buffer_free(sync_ctx.mails);
+	buffer_free(sync_ctx.syncs);
 	return ret;
 }
 



More information about the dovecot-cvs mailing list