[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-save.c, 1.74, 1.75 maildir-storage.h, 1.53, 1.54 maildir-sync.c, 1.83, 1.84

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


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

Modified Files:
	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.74
retrieving revision 1.75
diff -u -d -r1.74 -r1.75
--- maildir-save.c	1 Jul 2006 18:33:04 -0000	1.74
+++ maildir-save.c	7 Nov 2006 21:22:08 -0000	1.75
@@ -475,7 +475,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);
@@ -503,6 +503,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);
@@ -535,7 +536,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) {
@@ -599,7 +603,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.53
retrieving revision 1.54
diff -u -d -r1.53 -r1.54
--- maildir-storage.h	28 Jun 2006 16:31:07 -0000	1.53
+++ maildir-storage.h	7 Nov 2006 21:22:08 -0000	1.54
@@ -112,7 +112,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);
 
 void maildir_transaction_created(struct mail_index_transaction *t);
 void maildir_transaction_class_init(void);

Index: maildir-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-sync.c,v
retrieving revision 1.83
retrieving revision 1.84
diff -u -d -r1.83 -r1.84
--- maildir-sync.c	17 Sep 2006 17:28:36 -0000	1.83
+++ maildir-sync.c	7 Nov 2006 21:22:08 -0000	1.84
@@ -612,8 +612,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,
@@ -878,7 +880,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;
@@ -889,7 +891,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,
@@ -901,7 +903,7 @@
 			}
 		}
 	}
-	if (ret < 0)
+	if (ret < 0 || cancel)
 		mail_index_sync_rollback(&sync_ctx->sync_ctx);
 	else {
 		/* Set syncing_commit=TRUE so that if any sync callbacks try
@@ -1335,7 +1337,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