[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-sync.c, 1.15, 1.16

cras at procontrol.fi cras at procontrol.fi
Mon Jun 14 00:50:45 EEST 2004


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

Modified Files:
	mbox-sync.c 
Log Message:
Don't sync mbox if it hasn't changed



Index: mbox-sync.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-storage/index/mbox/mbox-sync.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -d -r1.15 -r1.16
--- mbox-sync.c	13 Jun 2004 20:39:17 -0000	1.15
+++ mbox-sync.c	13 Jun 2004 21:50:42 -0000	1.16
@@ -207,6 +207,7 @@
 			struct mail_index_view *sync_view,
 			buffer_t *syncs, struct mail_index_sync_rec *sync_rec)
 {
+	/* a horrible function. needs some serious cleanups. */
 	struct mbox_sync_context sync_ctx;
 	struct mbox_sync_mail_context mail_ctx;
 	struct mail_index_transaction *t;
@@ -583,7 +584,7 @@
 			offsetof(struct mail_index_header, sync_stamp),
 			&sync_stamp, sizeof(sync_stamp));
 	}
-	if ((uint64_t)st.st_mtime != hdr->sync_size) {
+	if ((uint64_t)st.st_size != hdr->sync_size) {
 		uint64_t sync_size = st.st_size;
 
 		mail_index_update_header(t,
@@ -623,10 +624,29 @@
 	return ret < 0 ? ret : 0;
 }
 
+static int mbox_sync_has_changed(struct index_mailbox *ibox)
+{
+	const struct mail_index_header *hdr;
+	struct stat st;
+
+	if (mail_index_get_header(ibox->view, &hdr) < 0) {
+		mail_storage_set_index_error(ibox);
+		return -1;
+	}
+
+	if (stat(ibox->path, &st) < 0) {
+		mbox_set_syscall_error(ibox, "stat()");
+		return -1;
+	}
+
+	return (uint32_t)st.st_mtime != hdr->sync_stamp ||
+		(uint64_t)st.st_size != hdr->sync_size;
+}
+
 int mbox_sync(struct index_mailbox *ibox, int last_commit)
 {
 	struct mail_index_sync_ctx *index_sync_ctx;
-        struct mail_index_view *sync_view;
+	struct mail_index_view *sync_view;
 	unsigned int lock_id;
 	uint32_t seq;
 	uoff_t offset;
@@ -634,6 +654,9 @@
 	buffer_t *syncs;
 	int ret, lock_type;
 
+	if ((ret = mbox_sync_has_changed(ibox)) <= 0)
+		return ret;
+
 	if (last_commit) {
 		seq = ibox->commit_log_file_seq;
 		offset = ibox->commit_log_file_offset;
@@ -644,8 +667,11 @@
 
 	ret = mail_index_sync_begin(ibox->index, &index_sync_ctx, &sync_view,
 				    seq, offset);
-	if (ret <= 0)
+	if (ret <= 0) {
+		if (ret < 0)
+			mail_storage_set_index_error(ibox);
 		return ret;
+	}
 
 	memset(&sync_rec, 0, sizeof(sync_rec));
 	syncs = buffer_create_dynamic(default_pool, 256, (size_t)-1);



More information about the dovecot-cvs mailing list