dovecot: When saving to empty mbox files, sync them first since ...

dovecot at dovecot.org dovecot at dovecot.org
Sun Oct 21 03:33:25 EEST 2007


details:   http://hg.dovecot.org/dovecot/rev/104a8929ef7c
changeset: 6583:104a8929ef7c
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Oct 21 03:33:21 2007 +0300
description:
When saving to empty mbox files, sync them first since it doesn't take
hardly any time anyway.

diffstat:

3 files changed, 14 insertions(+), 2 deletions(-)
src/lib-storage/index/mbox/mbox-save.c         |    5 +++--
src/lib-storage/index/mbox/mbox-sync-private.h |    2 ++
src/lib-storage/index/mbox/mbox-sync.c         |    9 +++++++++

diffs (67 lines):

diff -r 9e7bf6becfb4 -r 104a8929ef7c src/lib-storage/index/mbox/mbox-save.c
--- a/src/lib-storage/index/mbox/mbox-save.c	Sun Oct 21 03:09:33 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-save.c	Sun Oct 21 03:33:21 2007 +0300
@@ -267,6 +267,7 @@ mbox_save_init_file(struct mbox_save_con
 {
 	struct mbox_mailbox *mbox = ctx->mbox;
 	struct mail_storage *storage = &mbox->storage->storage;
+	bool empty = FALSE;
 	int ret;
 
 	if (ctx->mbox->mbox_readonly) {
@@ -300,7 +301,7 @@ mbox_save_init_file(struct mbox_save_con
 		}
 
 		/* update mbox_sync_dirty state */
-		ret = mbox_sync_has_changed(mbox, TRUE);
+		ret = mbox_sync_has_changed_full(mbox, TRUE, &empty);
 		if (ret < 0)
 			return -1;
 		if (!want_mail && ret == 0) {
@@ -311,7 +312,7 @@ mbox_save_init_file(struct mbox_save_con
 		}
 	}
 
-	if (!ctx->synced && want_mail) {
+	if (!ctx->synced && (want_mail || empty)) {
 		/* we'll need to assign UID for the mail immediately. */
 		if (mbox_sync(mbox, 0) < 0)
 			return -1;
diff -r 9e7bf6becfb4 -r 104a8929ef7c src/lib-storage/index/mbox/mbox-sync-private.h
--- a/src/lib-storage/index/mbox/mbox-sync-private.h	Sun Oct 21 03:09:33 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-private.h	Sun Oct 21 03:33:21 2007 +0300
@@ -147,6 +147,8 @@ struct mbox_sync_context {
 
 int mbox_sync(struct mbox_mailbox *mbox, enum mbox_sync_flags flags);
 int mbox_sync_has_changed(struct mbox_mailbox *mbox, bool leave_dirty);
+int mbox_sync_has_changed_full(struct mbox_mailbox *mbox, bool leave_dirty,
+			       bool *empty_r);
 void mbox_sync_set_critical(struct mbox_sync_context *sync_ctx,
 			    const char *fmt, ...) ATTR_FORMAT(2, 3);
 
diff -r 9e7bf6becfb4 -r 104a8929ef7c src/lib-storage/index/mbox/mbox-sync.c
--- a/src/lib-storage/index/mbox/mbox-sync.c	Sun Oct 21 03:09:33 2007 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Sun Oct 21 03:33:21 2007 +0300
@@ -1483,6 +1483,14 @@ static int mbox_sync_do(struct mbox_sync
 
 int mbox_sync_has_changed(struct mbox_mailbox *mbox, bool leave_dirty)
 {
+	bool empty;
+
+	return mbox_sync_has_changed_full(mbox, leave_dirty, &empty);
+}
+
+int mbox_sync_has_changed_full(struct mbox_mailbox *mbox, bool leave_dirty,
+			       bool *empty_r)
+{
 	const struct mail_index_header *hdr;
 	const struct stat *st;
 	struct stat statbuf;
@@ -1501,6 +1509,7 @@ int mbox_sync_has_changed(struct mbox_ma
 		}
 		st = &statbuf;
 	}
+	*empty_r = st->st_size == 0;
 
 	hdr = mail_index_get_header(mbox->ibox.view);
 


More information about the dovecot-cvs mailing list