[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-save.c, 1.70.2.2, 1.70.2.3 maildir-storage.h, 1.49.2.1, 1.49.2.2 maildir-sync.c, 1.77.2.2, 1.77.2.3

tss at dovecot.org tss at dovecot.org
Tue Nov 7 21:22:09 UTC 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index/maildir
In directory talvi:/tmp/cvs-serv2841

Modified Files:
      Tag: branch_1_0
	maildir-save.c maildir-storage.h maildir-sync.c 
Log Message:
Saving mails could have skipped over transactions, which caused different
kinds of problems.



Index: maildir-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-save.c,v
retrieving revision 1.70.2.2
retrieving revision 1.70.2.3
diff -u -d -r1.70.2.2 -r1.70.2.3
--- maildir-save.c	1 Jul 2006 18:33:03 -0000	1.70.2.2
+++ maildir-save.c	7 Nov 2006 21:22:06 -0000	1.70.2.3
@@ -447,7 +447,7 @@
 	uint32_t first_uid, last_uid;
 	enum maildir_uidlist_rec_flag flags;
 	const char *dest;
-	bool newdir;
+	bool newdir, sync_commit = FALSE;
 	int ret;
 
 	i_assert(ctx->output == NULL);
@@ -475,6 +475,7 @@
 			maildir_transaction_save_rollback(ctx);
 			return -1;
 		}
+		sync_commit = TRUE;
 
 		first_uid = maildir_uidlist_get_next_uid(ctx->mbox->uidlist);
 		mail_index_append_assign_uids(ctx->trans, first_uid, &last_uid);
@@ -507,7 +508,10 @@
 		t_pop();
 	}
 
-	if (maildir_sync_index_finish(&ctx->sync_ctx, ret < 0) < 0)
+	/* if we didn't call maildir_sync_index() we could skip over
+	   transactions by committing the changes */
+	if (maildir_sync_index_finish(&ctx->sync_ctx, ret < 0,
+				      !sync_commit) < 0)
 		ret = -1;
 
 	if (ret < 0) {
@@ -568,7 +572,7 @@
 	if (ctx->uidlist_sync_ctx != NULL)
 		(void)maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx);
 	if (ctx->sync_ctx != NULL)
-		(void)maildir_sync_index_finish(&ctx->sync_ctx, TRUE);
+		(void)maildir_sync_index_finish(&ctx->sync_ctx, TRUE, FALSE);
 
 	t_pop();
 

Index: maildir-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.h,v
retrieving revision 1.49.2.1
retrieving revision 1.49.2.2
diff -u -d -r1.49.2.1 -r1.49.2.2
--- maildir-storage.h	11 Jun 2006 14:06:08 -0000	1.49.2.1
+++ maildir-storage.h	7 Nov 2006 21:22:06 -0000	1.49.2.2
@@ -111,7 +111,7 @@
 int maildir_sync_index(struct maildir_index_sync_context *sync_ctx,
 		       bool partial);
 int maildir_sync_index_finish(struct maildir_index_sync_context **sync_ctx,
-			      bool failed);
+			      bool failed, bool cancel);
 
 struct mailbox_transaction_context *
 maildir_transaction_begin(struct mailbox *box,

Index: maildir-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-sync.c,v
retrieving revision 1.77.2.2
retrieving revision 1.77.2.3
diff -u -d -r1.77.2.2 -r1.77.2.3
--- maildir-sync.c	27 Jun 2006 22:51:45 -0000	1.77.2.2
+++ maildir-sync.c	7 Nov 2006 21:22:06 -0000	1.77.2.3
@@ -614,8 +614,10 @@
 {
 	if (ctx->uidlist_sync_ctx != NULL)
 		(void)maildir_uidlist_sync_deinit(&ctx->uidlist_sync_ctx);
-	if (ctx->index_sync_ctx != NULL)
-		(void)maildir_sync_index_finish(&ctx->index_sync_ctx, TRUE);
+	if (ctx->index_sync_ctx != NULL) {
+		(void)maildir_sync_index_finish(&ctx->index_sync_ctx,
+						TRUE, FALSE);
+	}
 }
 
 static int maildir_fix_duplicate(struct maildir_sync_context *ctx,
@@ -880,7 +882,7 @@
 }
 
 int maildir_sync_index_finish(struct maildir_index_sync_context **_sync_ctx,
-			      bool failed)
+			      bool failed, bool cancel)
 {
 	struct maildir_index_sync_context *sync_ctx = *_sync_ctx;
 	struct maildir_mailbox *mbox = sync_ctx->mbox;
@@ -891,7 +893,7 @@
 	*_sync_ctx = NULL;
 
 	if (sync_ctx->trans != NULL) {
-		if (ret < 0)
+		if (ret < 0 || cancel)
 			mail_index_transaction_rollback(&sync_ctx->trans);
 		else {
 			if (mail_index_transaction_commit(&sync_ctx->trans,
@@ -903,7 +905,7 @@
 			}
 		}
 	}
-	if (ret < 0)
+	if (ret < 0 || cancel)
 		mail_index_sync_rollback(&sync_ctx->sync_ctx);
 	else {
 		if (mail_index_sync_commit(&sync_ctx->sync_ctx) < 0)
@@ -1333,7 +1335,7 @@
 		   maildir_uidlist_sync_deinit() */
 		ret = maildir_sync_index(ctx->index_sync_ctx, ctx->partial);
 		if (maildir_sync_index_finish(&ctx->index_sync_ctx,
-					      ret < 0) < 0)
+					      ret < 0, FALSE) < 0)
 			return -1;
 
 		if (ret < 0)



More information about the dovecot-cvs mailing list