changeset 6089:a19931ec66db HEAD

Changed mail_transaction_begin() API to take flags parameter instead of two booleans.
author Timo Sirainen <tss@iki.fi>
date Thu, 19 Jul 2007 02:36:04 +0300
parents 7639a6df4acb
children 56f8a4dd819d
files src/imap/imap-thread.c src/lib-index/mail-index-sync.c src/lib-index/mail-index-transaction-private.h src/lib-index/mail-index-transaction.c src/lib-index/mail-index.h src/lib-index/mail-transaction-log-append.c src/lib-storage/index/index-transaction.c src/lib-storage/list/index-mailbox-list-sync.c
diffstat 8 files changed, 32 insertions(+), 25 deletions(-) [+]
line wrap: on
line diff
--- a/src/imap/imap-thread.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/imap/imap-thread.c	Thu Jul 19 02:36:04 2007 +0300
@@ -2082,7 +2082,7 @@
 		if (mail_hash_lock(tbox->msgid_hash) <= 0)
 			return 0;
 
-		t = mail_index_transaction_begin(sync_ctx->view, FALSE, FALSE);
+		t = mail_index_transaction_begin(sync_ctx->view, 0);
 		mt = MAIL_STORAGE_CONTEXT(t);
 
 		ctx->msgid_hash = tbox->msgid_hash;
--- a/src/lib-index/mail-index-sync.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-index-sync.c	Thu Jul 19 02:36:04 2007 +0300
@@ -364,7 +364,8 @@
 	ctx->view = mail_index_view_open(index);
 
 	sync_view = mail_index_dummy_view_open(index);
-	ctx->sync_trans = mail_index_transaction_begin(sync_view, FALSE, TRUE);
+	ctx->sync_trans = mail_index_transaction_begin(sync_view,
+					MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
 	mail_index_view_close(&sync_view);
 
 	/* we wish to see all the changes from last mailbox sync position to
@@ -394,7 +395,8 @@
 
 	/* create the transaction after the view has been updated with
 	   external transactions and marked as sync view */
-	ctx->ext_trans = mail_index_transaction_begin(ctx->view, FALSE, TRUE);
+	ctx->ext_trans = mail_index_transaction_begin(ctx->view,
+					MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
 
 	*ctx_r = ctx;
 	*view_r = ctx->view;
--- a/src/lib-index/mail-index-transaction-private.h	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-index-transaction-private.h	Thu Jul 19 02:36:04 2007 +0300
@@ -29,6 +29,7 @@
 struct mail_index_transaction {
 	int refcount;
 
+	enum mail_index_transaction_flags flags;
 	struct mail_index_transaction_vfuncs v;
 	struct mail_index_view *view;
 
@@ -65,9 +66,7 @@
 
 	/* this transaction was created for index_sync_view view */
 	unsigned int sync_transaction:1;
-	unsigned int hide_transaction:1;
 	unsigned int no_appends:1;
-	unsigned int external:1;
 
 	unsigned int appends_nonsorted:1;
 	unsigned int pre_hdr_changed:1;
--- a/src/lib-index/mail-index-transaction.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-index-transaction.c	Thu Jul 19 02:36:04 2007 +0300
@@ -590,7 +590,6 @@
 
 void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq)
 {
-	i_assert(!t->hide_transaction);
 	i_assert(seq > 0 && seq <= mail_index_view_get_messages_count(t->view));
 
 	t->log_updates = TRUE;
@@ -1196,7 +1195,7 @@
 
 struct mail_index_transaction *
 mail_index_transaction_begin(struct mail_index_view *view,
-			     bool hide, bool external)
+			     enum mail_index_transaction_flags flags)
 {
 	struct mail_index_transaction *t;
 
@@ -1208,8 +1207,7 @@
 	t->refcount = 1;
 	t->v = trans_vfuncs;
 	t->view = view;
-	t->hide_transaction = hide;
-	t->external = external;
+	t->flags = flags;
 	t->sync_transaction = view->index_sync_view;
 
 	if (view->syncing) {
--- a/src/lib-index/mail-index.h	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-index.h	Thu Jul 19 02:36:04 2007 +0300
@@ -100,6 +100,15 @@
 	unsigned int idx[1];
 };
 
+enum mail_index_transaction_flags {
+	/* If transaction is marked as hidden, the changes won't be listed
+	   when the view is synchronized. */
+	MAIL_INDEX_TRANSACTION_FLAG_HIDE		= 0x01,
+	/* External transactions describe changes to mailbox that have already
+	   happened. */
+	MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL		= 0x02
+};
+
 enum mail_index_sync_type {
 	MAIL_INDEX_SYNC_TYPE_APPEND		= 0x01,
 	MAIL_INDEX_SYNC_TYPE_EXPUNGE		= 0x02,
@@ -187,16 +196,10 @@
 /* Transaction has to be opened to be able to modify index. You can have
    multiple transactions open simultaneously. Committed transactions won't
    show up until you've synchronized the view. Expunges won't show up until
-   you've synchronized the mailbox (mail_index_sync_begin).
-
-   If transaction is marked as hidden, the changes won't be listed when the
-   view is synchronized. Expunges can't be hidden.
-
-   External transactions describe changes to mailbox that have already
-   happened. */
+   you've synchronized the mailbox (mail_index_sync_begin). */
 struct mail_index_transaction *
 mail_index_transaction_begin(struct mail_index_view *view,
-			     bool hide, bool external);
+			     enum mail_index_transaction_flags flags);
 int mail_index_transaction_commit(struct mail_index_transaction **t,
 				  uint32_t *log_file_seq_r,
 				  uoff_t *log_file_offset_r);
--- a/src/lib-index/mail-transaction-log-append.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-index/mail-transaction-log-append.c	Thu Jul 19 02:36:04 2007 +0300
@@ -36,7 +36,7 @@
 	hdr.type = type;
 	if (type == MAIL_TRANSACTION_EXPUNGE)
 		hdr.type |= MAIL_TRANSACTION_EXPUNGE_PROT;
-	if (ctx->trans->external)
+	if ((ctx->trans->flags & MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0)
 		hdr.type |= MAIL_TRANSACTION_EXTERNAL;
 
 	hdr_size = mail_index_uint32_to_offset(sizeof(hdr) + buf->used +
@@ -536,7 +536,7 @@
 	/* NOTE: mailbox sync offset update must be the last change.
 	   it may update the sync offset to include this transaction, so it
 	   needs to know this transaction's size */
-	if (t->external)
+	if ((t->flags & MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0)
 		log_append_sync_offset_if_needed(&ctx);
 
 	if (file->sync_offset < file->last_size) {
@@ -560,7 +560,7 @@
 	}
 	buffer_free(ctx.output);
 
-	if (t->hide_transaction) {
+	if ((t->flags & MAIL_INDEX_TRANSACTION_FLAG_HIDE) != 0) {
 		/* mark the area covered by this transaction hidden */
 		mail_index_view_add_hidden_transaction(view, file->hdr.file_seq,
 			append_offset, file->sync_offset - append_offset);
@@ -588,7 +588,8 @@
 
 	index = mail_index_view_get_index(t->view);
 	if (index->log_locked) {
-		i_assert(t->external);
+		i_assert((t->flags &
+			  MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0);
 	} else {
 		if (mail_transaction_log_lock_head(index->log) < 0)
 			return -1;
--- a/src/lib-storage/index/index-transaction.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-storage/index/index-transaction.c	Thu Jul 19 02:36:04 2007 +0300
@@ -61,13 +61,16 @@
 	struct index_mailbox *ibox = (struct index_mailbox *)box;
 	struct mail_index_transaction *t;
 	struct index_transaction_context *it;
+	enum mail_index_transaction_flags trans_flags = 0;
 
 	if (!box->opened)
 		index_storage_mailbox_open(ibox);
 
-	t = mail_index_transaction_begin(ibox->view,
-		(flags & MAILBOX_TRANSACTION_FLAG_HIDE) != 0,
-		(flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0);
+	if ((flags & MAILBOX_TRANSACTION_FLAG_HIDE) != 0)
+		trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_HIDE;
+	if ((flags & MAILBOX_TRANSACTION_FLAG_EXTERNAL) != 0)
+		trans_flags |= MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL;
+	t = mail_index_transaction_begin(ibox->view, trans_flags);
 
 	it = MAIL_STORAGE_CONTEXT(t);
 	if (it == NULL) {
--- a/src/lib-storage/list/index-mailbox-list-sync.c	Thu Jul 19 02:13:44 2007 +0300
+++ b/src/lib-storage/list/index-mailbox-list-sync.c	Thu Jul 19 02:36:04 2007 +0300
@@ -227,7 +227,8 @@
 	unsigned int i;
 	int ret = 1;
 
-	trans = mail_index_transaction_begin(view, FALSE, TRUE);
+	trans = mail_index_transaction_begin(view,
+					MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
 
 	/* update counters */
 	for (i = 0; index_list_map[i].name != NULL; i++) {