changeset 2665:ccf563859be5 HEAD

Split sync_flag_full into sync_flag_full_read and _write. Closing mailbox now always writes changes.
author Timo Sirainen <tss@iki.fi>
date Fri, 24 Sep 2004 14:47:30 +0300
parents f54b0f04c628
children 0ba82d7a5aba
files src/imap/cmd-check.c src/imap/cmd-logout.c src/imap/cmd-select.c src/imap/imap-expunge.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/mbox/mbox-sync-private.h src/lib-storage/index/mbox/mbox-sync.c src/lib-storage/index/mbox/mbox-transaction.c src/lib-storage/mail-storage.h src/pop3/client.c
diffstat 10 files changed, 44 insertions(+), 23 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/cmd-check.c	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/imap/cmd-check.c	Fri Sep 24 14:47:30 2004 +0300
@@ -8,5 +8,6 @@
 	if (!client_verify_open_mailbox(client))
 		return TRUE;
 
-	return cmd_sync(client, MAILBOX_SYNC_FLAG_FULL, "OK Check completed.");
+	return cmd_sync(client, MAILBOX_SYNC_FLAG_FULL_READ |
+			MAILBOX_SYNC_FLAG_FULL_WRITE, "OK Check completed.");
 }
--- a/src/imap/cmd-logout.c	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/imap/cmd-logout.c	Fri Sep 24 14:47:30 2004 +0300
@@ -11,14 +11,6 @@
 		/* this could be done at client_disconnect() as well,
 		   but eg. mbox rewrite takes a while so the waiting is
 		   better to happen before "OK" message. */
-		if (imap_sync_nonselected(client->mailbox,
-					  MAILBOX_SYNC_FLAG_FULL) < 0) {
-			client_send_storage_error(client,
-				mailbox_get_storage(client->mailbox));
-			mailbox_close(client->mailbox);
-			return TRUE;
-		}
-
 		mailbox_close(client->mailbox);
 		client->mailbox = NULL;
 	}
--- a/src/imap/cmd-select.c	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/imap/cmd-select.c	Fri Sep 24 14:47:30 2004 +0300
@@ -35,7 +35,7 @@
 		return TRUE;
 	}
 
-	if (imap_sync_nonselected(box, 0) < 0) {
+	if (imap_sync_nonselected(box, MAILBOX_SYNC_FLAG_FULL_READ) < 0) {
 		client_send_storage_error(client, storage);
 		mailbox_close(box);
 		return TRUE;
--- a/src/imap/imap-expunge.c	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/imap/imap-expunge.c	Fri Sep 24 14:47:30 2004 +0300
@@ -10,7 +10,8 @@
 	struct mail_search_context *ctx;
         struct mailbox_transaction_context *t;
 	struct mail *mail;
-        struct mail_search_arg search_arg;
+	struct mail_search_arg search_arg;
+        enum mailbox_sync_flags flags;
 	int failed = FALSE;
 
 	memset(&search_arg, 0, sizeof(search_arg));
@@ -36,7 +37,9 @@
 	if (failed)
 		mailbox_transaction_rollback(t);
 	else {
-		if (mailbox_transaction_commit(t, MAILBOX_SYNC_FLAG_FULL) < 0)
+		flags = MAILBOX_SYNC_FLAG_FULL_READ |
+			MAILBOX_SYNC_FLAG_FULL_WRITE;
+		if (mailbox_transaction_commit(t, flags) < 0)
 			failed = TRUE;
 	}
 
--- a/src/lib-storage/index/mbox/mbox-storage.c	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Fri Sep 24 14:47:30 2004 +0300
@@ -9,6 +9,7 @@
 #include "mbox-storage.h"
 #include "mbox-lock.h"
 #include "mbox-file.h"
+#include "mbox-sync-private.h"
 #include "mail-copy.h"
 
 #include <stdio.h>
@@ -788,10 +789,21 @@
 static int mbox_storage_close(struct mailbox *box)
 {
 	struct index_mailbox *ibox = (struct index_mailbox *)box;
+	const struct mail_index_header *hdr;
+	int ret;
+
+	ret = mail_index_get_header(ibox->view, &hdr);
+	if (ret == 0 && (hdr->flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0 &&
+	    !ibox->readonly && !ibox->mbox_readonly) {
+		/* we've done changes to mbox which haven't been written yet.
+		   do it now. */
+		if (mbox_sync(ibox, MBOX_SYNC_REWRITE) < 0)
+			ret = -1;
+	}
 
         mbox_file_close(ibox);
         index_storage_mailbox_free(box);
-	return 0;
+	return ret;
 }
 
 static void
--- a/src/lib-storage/index/mbox/mbox-sync-private.h	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync-private.h	Fri Sep 24 14:47:30 2004 +0300
@@ -8,7 +8,8 @@
 	MBOX_SYNC_LAST_COMMIT	= 0x01,
 	MBOX_SYNC_HEADER	= 0x02,
 	MBOX_SYNC_LOCK_READING	= 0x04,
-	MBOX_SYNC_UNDIRTY	= 0x08
+	MBOX_SYNC_UNDIRTY	= 0x08,
+	MBOX_SYNC_REWRITE	= 0x10
 };
 
 struct mbox_flag_type {
--- a/src/lib-storage/index/mbox/mbox-sync.c	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Fri Sep 24 14:47:30 2004 +0300
@@ -407,7 +407,7 @@
 
 		if (mail_ctx->dirty)
 			mbox_flags |= MAIL_INDEX_MAIL_FLAG_DIRTY;
-		else if ((sync_ctx->flags & MBOX_SYNC_UNDIRTY) != 0)
+		else if (!sync_ctx->delay_writes)
 			mbox_flags &= ~MAIL_INDEX_MAIL_FLAG_DIRTY;
 
 		if ((idx_flags & ~MAIL_INDEX_MAIL_FLAG_DIRTY) ==
@@ -1316,7 +1316,8 @@
 	sync_ctx.fd = sync_ctx.ibox->mbox_fd;
 	sync_ctx.flags = flags;
 	sync_ctx.delay_writes = sync_ctx.ibox->mbox_readonly ||
-		((flags & MBOX_SYNC_UNDIRTY) == 0 &&
+		sync_ctx.ibox->readonly ||
+		((flags & MBOX_SYNC_REWRITE) == 0 &&
 		 getenv("MBOX_LAZY_WRITES") != NULL);
 
 
@@ -1419,8 +1420,10 @@
 
 	if ((flags & MAILBOX_SYNC_FLAG_FAST) == 0 ||
 	    ibox->sync_last_check + MAILBOX_FULL_SYNC_INTERVAL <= ioloop_time) {
-		if ((flags & MAILBOX_SYNC_FLAG_FULL) != 0)
+		if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0)
 			mbox_sync_flags |= MBOX_SYNC_UNDIRTY;
+		if ((flags & MAILBOX_SYNC_FLAG_FULL_WRITE) != 0)
+			mbox_sync_flags |= MBOX_SYNC_REWRITE;
 		ret = mbox_sync(ibox, mbox_sync_flags);
 	}
 
--- a/src/lib-storage/index/mbox/mbox-transaction.c	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/lib-storage/index/mbox/mbox-transaction.c	Fri Sep 24 14:47:30 2004 +0300
@@ -39,8 +39,10 @@
 
 	if (ret == 0) {
 		enum mbox_sync_flags mbox_sync_flags = MBOX_SYNC_LAST_COMMIT;
-		if ((flags & MAILBOX_SYNC_FLAG_FULL) != 0)
+		if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0)
 			mbox_sync_flags |= MBOX_SYNC_UNDIRTY;
+		if ((flags & MAILBOX_SYNC_FLAG_FULL_WRITE) != 0)
+			mbox_sync_flags |= MBOX_SYNC_REWRITE;
 		if (mbox_modified)
 			mbox_sync_flags |= MBOX_SYNC_HEADER;
 		if (mbox_sync(ibox, mbox_sync_flags) < 0)
--- a/src/lib-storage/mail-storage.h	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/lib-storage/mail-storage.h	Fri Sep 24 14:47:30 2004 +0300
@@ -86,10 +86,17 @@
 };
 
 enum mailbox_sync_flags {
-	MAILBOX_SYNC_FLAG_FULL		= 0x01,
-	MAILBOX_SYNC_FLAG_FAST		= 0x02,
-	MAILBOX_SYNC_FLAG_NO_EXPUNGES	= 0x04,
-	MAILBOX_SYNC_AUTO_STOP		= 0x08
+	/* Make sure we sync all external changes done to mailbox */
+	MAILBOX_SYNC_FLAG_FULL_READ	= 0x01,
+	/* Make sure we write all our internal changes into the mailbox */
+	MAILBOX_SYNC_FLAG_FULL_WRITE	= 0x02,
+	/* If it's not too much trouble, check if there are some changes */
+	MAILBOX_SYNC_FLAG_FAST		= 0x04,
+
+	/* Don't sync expunges from our view */
+	MAILBOX_SYNC_FLAG_NO_EXPUNGES	= 0x08,
+	/* Stop auto syncing */
+	MAILBOX_SYNC_AUTO_STOP		= 0x10
 };
 
 enum mailbox_sync_type {
--- a/src/pop3/client.c	Fri Sep 24 14:44:33 2004 +0300
+++ b/src/pop3/client.c	Fri Sep 24 14:47:30 2004 +0300
@@ -42,7 +42,7 @@
         struct mailbox_sync_rec sync_rec;
 	struct mailbox_status status;
 
-	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL);
+	ctx = mailbox_sync_init(box, MAILBOX_SYNC_FLAG_FULL_READ);
 	while (mailbox_sync_next(ctx, &sync_rec) > 0)
 		;
 	return mailbox_sync_deinit(ctx, &status);