[dovecot-cvs] dovecot/src/lib-storage/index/mbox mbox-storage.c, 1.148, 1.149 mbox-storage.h, 1.44, 1.45 mbox-transaction.c, 1.13, 1.14

tss-movial at dovecot.org tss-movial at dovecot.org
Wed Jun 28 19:31:13 EEST 2006


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

Modified Files:
	mbox-storage.c mbox-storage.h mbox-transaction.c 
Log Message:
Beginnings of joining mail-storage API more closely to mail-index, so that
mail-index could be directly used if needed. Currently only transactions
are joined.



Index: mbox-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.c,v
retrieving revision 1.148
retrieving revision 1.149
diff -u -d -r1.148 -r1.149
--- mbox-storage.c	17 Jun 2006 13:04:34 -0000	1.148
+++ mbox-storage.c	28 Jun 2006 16:31:09 -0000	1.149
@@ -1085,11 +1085,23 @@
 		index_mailbox_check_add(&mbox->ibox, mbox->path);
 }
 
+static void mbox_class_init(void)
+{
+	mbox_transaction_class_init();
+}
+
+static void mbox_class_deinit(void)
+{
+	mbox_transaction_class_deinit();
+}
+
 struct mail_storage mbox_storage = {
-	MEMBER(name) "mbox",
+	MEMBER(name) MBOX_STORAGE_NAME,
 	MEMBER(hierarchy_sep) '/',
 
 	{
+		mbox_class_init,
+		mbox_class_deinit,
 		mbox_create,
 		mbox_free,
 		mbox_autodetect,
@@ -1122,9 +1134,9 @@
 		index_mailbox_sync_next,
 		index_mailbox_sync_deinit,
 		mbox_notify_changes,
-		mbox_transaction_begin,
-		mbox_transaction_commit,
-		mbox_transaction_rollback,
+		index_transaction_begin,
+		index_transaction_commit,
+		index_transaction_rollback,
 		index_keywords_create,
 		index_keywords_free,
 		index_storage_get_uids,

Index: mbox-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-storage.h,v
retrieving revision 1.44
retrieving revision 1.45
diff -u -d -r1.44 -r1.45
--- mbox-storage.h	9 May 2006 11:57:39 -0000	1.44
+++ mbox-storage.h	28 Jun 2006 16:31:09 -0000	1.45
@@ -6,6 +6,7 @@
 /* Don't write Content-Length header unless it's value is larger than this. */
 #define MBOX_MIN_CONTENT_LENGTH_SIZE 1024
 
+#define MBOX_STORAGE_NAME "mbox"
 #define SUBSCRIPTION_FILE_NAME ".subscriptions"
 #define MBOX_INDEX_PREFIX "dovecot.index"
 #define MBOX_INDEX_DIR_NAME ".imap"
@@ -70,12 +71,9 @@
 int mbox_mailbox_list_deinit(struct mailbox_list_context *ctx);
 struct mailbox_list *mbox_mailbox_list_next(struct mailbox_list_context *ctx);
 
-struct mailbox_transaction_context *
-mbox_transaction_begin(struct mailbox *box,
-		       enum mailbox_transaction_flags flags);
-int mbox_transaction_commit(struct mailbox_transaction_context *t,
-			    enum mailbox_sync_flags flags);
-void mbox_transaction_rollback(struct mailbox_transaction_context *t);
+void mbox_transaction_created(struct mail_index_transaction *t);
+void mbox_transaction_class_init(void);
+void mbox_transaction_class_deinit(void);
 
 struct mailbox_sync_context *
 mbox_storage_sync_init(struct mailbox *box, enum mailbox_sync_flags flags);

Index: mbox-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/mbox/mbox-transaction.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- mbox-transaction.c	13 Jan 2006 20:26:37 -0000	1.13
+++ mbox-transaction.c	28 Jun 2006 16:31:09 -0000	1.14
@@ -1,43 +1,40 @@
 /* Copyright (C) 2004 Timo Sirainen */
 
 #include "lib.h"
+#include "array.h"
 #include "mbox-storage.h"
 #include "mbox-lock.h"
 #include "mbox-sync-private.h"
 
-struct mailbox_transaction_context *
-mbox_transaction_begin(struct mailbox *box,
-		       enum mailbox_transaction_flags flags)
-{
-	struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
-	struct mbox_transaction_context *t;
-
-	t = i_new(struct mbox_transaction_context, 1);
-	index_transaction_init(&t->ictx, &mbox->ibox, flags);
-	return &t->ictx.mailbox_ctx;
-}
+static void (*next_hook_mail_index_transaction_created)
+	(struct mail_index_transaction *t) = NULL;
 
-int mbox_transaction_commit(struct mailbox_transaction_context *_t,
-			    enum mailbox_sync_flags flags)
+static int mbox_transaction_commit(struct mail_index_transaction *t,
+				   uint32_t *log_file_seq_r,
+				   uoff_t *log_file_offset_r)
 {
-	struct mbox_transaction_context *t =
-		(struct mbox_transaction_context *)_t;
-	struct mbox_mailbox *mbox = (struct mbox_mailbox *)t->ictx.ibox;
-	unsigned int lock_id = t->mbox_lock_id;
+	struct mbox_transaction_context *mt = MAIL_STORAGE_TRANSACTION(t);
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mt->ictx.ibox;
+	unsigned int lock_id = mt->mbox_lock_id;
+	enum mailbox_sync_flags flags = mt->ictx.commit_flags;
 	bool mbox_modified;
+	bool external = t->external;
 	int ret = 0;
 
-	if (t->save_ctx != NULL)
-		ret = mbox_transaction_save_commit(t->save_ctx);
-	mbox_modified = t->mbox_modified;
+	if (mt->save_ctx != NULL)
+		ret = mbox_transaction_save_commit(mt->save_ctx);
+	mbox_modified = mt->mbox_modified;
 
-	if (ret == 0) {
-		if (index_transaction_commit(_t) < 0)
+	if (ret < 0)
+		index_transaction_finish_rollback(&mt->ictx);
+	else {
+		if (index_transaction_finish_commit(&mt->ictx, log_file_seq_r,
+						    log_file_offset_r) < 0)
 			ret = -1;
-	} else {
-		index_transaction_rollback(_t);
 	}
-	t = NULL;
+
+	/* transaction is destroyed now. */
+	mt = NULL;
 
 	if (lock_id != 0 && mbox->mbox_lock_type != F_WRLCK) {
 		/* unlock before writing any changes */
@@ -45,7 +42,7 @@
 		lock_id = 0;
 	}
 
-	if (ret == 0) {
+	if (ret == 0 && !external) {
 		enum mbox_sync_flags mbox_sync_flags = MBOX_SYNC_LAST_COMMIT;
 		if ((flags & MAILBOX_SYNC_FLAG_FULL_READ) != 0 &&
 		    !mbox->mbox_very_dirty_syncs)
@@ -65,16 +62,55 @@
 	return ret;
 }
 
-void mbox_transaction_rollback(struct mailbox_transaction_context *_t)
+static void mbox_transaction_rollback(struct mail_index_transaction *t)
 {
-	struct mbox_transaction_context *t =
-		(struct mbox_transaction_context *)_t;
-	struct mbox_mailbox *mbox = (struct mbox_mailbox *)t->ictx.ibox;
+	struct mbox_transaction_context *mt = MAIL_STORAGE_TRANSACTION(t);
+	struct mbox_mailbox *mbox = (struct mbox_mailbox *)mt->ictx.ibox;
 
-	if (t->save_ctx != NULL)
-		mbox_transaction_save_rollback(t->save_ctx);
+	if (mt->save_ctx != NULL)
+		mbox_transaction_save_rollback(mt->save_ctx);
 
-	if (t->mbox_lock_id != 0)
-		(void)mbox_unlock(mbox, t->mbox_lock_id);
-	index_transaction_rollback(_t);
+	if (mt->mbox_lock_id != 0)
+		(void)mbox_unlock(mbox, mt->mbox_lock_id);
+	index_transaction_finish_rollback(&mt->ictx);
+}
+
+void mbox_transaction_created(struct mail_index_transaction *t)
+{
+	struct mailbox *box = MAIL_STORAGE_INDEX(t->view->index);
+
+	if (strcmp(box->storage->name, MBOX_STORAGE_NAME) == 0) {
+		struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
+		struct mbox_transaction_context *mt;
+
+		mt = i_new(struct mbox_transaction_context, 1);
+		mt->ictx.trans = t;
+		mt->ictx.super = t->v;
+
+		t->v.commit = mbox_transaction_commit;
+		t->v.rollback = mbox_transaction_rollback;
+
+		array_idx_set(&t->mail_index_transaction_module_contexts,
+			      mail_storage_mail_index_module_id, &mt);
+
+		index_transaction_init(&mt->ictx, &mbox->ibox);
+	}
+
+	if (next_hook_mail_index_transaction_created != NULL)
+		next_hook_mail_index_transaction_created(t);
+}
+
+void mbox_transaction_class_init(void)
+{
+	next_hook_mail_index_transaction_created =
+		hook_mail_index_transaction_created;
+	hook_mail_index_transaction_created = mbox_transaction_created;
+}
+
+void mbox_transaction_class_deinit(void)
+{
+	i_assert(hook_mail_index_transaction_created ==
+		 mbox_transaction_created);
+	hook_mail_index_transaction_created =
+		next_hook_mail_index_transaction_created;
 }



More information about the dovecot-cvs mailing list