changeset 2112:55d3864cc4f8 HEAD

Don't sync mbox if it hasn't changed
author Timo Sirainen <tss@iki.fi>
date Mon, 14 Jun 2004 00:50:42 +0300
parents eb26aa46686d
children c5817f302aa6
files src/lib-storage/index/mbox/mbox-sync.c
diffstat 1 files changed, 29 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-sync.c	Sun Jun 13 23:39:17 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Mon Jun 14 00:50:42 2004 +0300
@@ -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);