[dovecot-cvs] dovecot/src/lib-storage/index/dbox dbox-storage.c, 1.19, 1.20 dbox-storage.h, 1.13, 1.14 dbox-transaction.c, 1.2, 1.3

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


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

Modified Files:
	dbox-storage.c dbox-storage.h dbox-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: dbox-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-storage.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -d -r1.19 -r1.20
--- dbox-storage.c	17 Jun 2006 13:04:08 -0000	1.19
+++ dbox-storage.c	28 Jun 2006 16:31:07 -0000	1.20
@@ -667,11 +667,23 @@
 		t_strconcat(mbox->path, "/"DBOX_MAILDIR_NAME, NULL));
 }
 
+static void dbox_class_init(void)
+{
+	dbox_transaction_class_init();
+}
+
+static void dbox_class_deinit(void)
+{
+	dbox_transaction_class_deinit();
+}
+
 struct mail_storage dbox_storage = {
-	MEMBER(name) "dbox",
+	MEMBER(name) DBOX_STORAGE_NAME,
 	MEMBER(hierarchy_sep) '/',
 
 	{
+		dbox_class_init,
+		dbox_class_deinit,
 		dbox_create,
 		dbox_free,
 		dbox_autodetect,
@@ -704,9 +716,9 @@
 		index_mailbox_sync_next,
 		index_mailbox_sync_deinit,
 		dbox_notify_changes,
-		dbox_transaction_begin,
-		dbox_transaction_commit,
-		dbox_transaction_rollback,
+		index_transaction_begin,
+		index_transaction_commit,
+		index_transaction_rollback,
 		index_keywords_create,
 		index_keywords_free,
 		index_storage_get_uids,

Index: dbox-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-storage.h,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -d -r1.13 -r1.14
--- dbox-storage.h	28 Jun 2006 13:10:50 -0000	1.13
+++ dbox-storage.h	28 Jun 2006 16:31:07 -0000	1.14
@@ -4,6 +4,7 @@
 #include "index-storage.h"
 #include "dbox-format.h"
 
+#define DBOX_STORAGE_NAME "dbox"
 #define STORAGE(mbox_storage) \
 	(&(mbox_storage)->storage.storage)
 #define INDEX_STORAGE(mbox_storage) \
@@ -83,12 +84,9 @@
 int dbox_mailbox_list_deinit(struct mailbox_list_context *ctx);
 struct mailbox_list *dbox_mailbox_list_next(struct mailbox_list_context *ctx);
 
-struct mailbox_transaction_context *
-dbox_transaction_begin(struct mailbox *box,
-		       enum mailbox_transaction_flags flags);
-int dbox_transaction_commit(struct mailbox_transaction_context *t,
-			    enum mailbox_sync_flags flags);
-void dbox_transaction_rollback(struct mailbox_transaction_context *t);
+void dbox_transaction_created(struct mail_index_transaction *t);
+void dbox_transaction_class_init(void);
+void dbox_transaction_class_deinit(void);
 
 int dbox_save_init(struct mailbox_transaction_context *_t,
 		   enum mail_flags flags, struct mail_keywords *keywords,

Index: dbox-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-transaction.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- dbox-transaction.c	29 Jan 2006 09:54:32 -0000	1.2
+++ dbox-transaction.c	28 Jun 2006 16:31:07 -0000	1.3
@@ -1,47 +1,42 @@
 /* Copyright (C) 2005 Timo Sirainen */
 
 #include "lib.h"
+#include "array.h"
 #include "dbox-sync.h"
 #include "dbox-storage.h"
 
-struct mailbox_transaction_context *
-dbox_transaction_begin(struct mailbox *box,
-		       enum mailbox_transaction_flags flags)
-{
-	struct dbox_mailbox *dbox = (struct dbox_mailbox *)box;
-	struct dbox_transaction_context *t;
-
-	t = i_new(struct dbox_transaction_context, 1);
-	index_transaction_init(&t->ictx, &dbox->ibox, flags);
-	return &t->ictx.mailbox_ctx;
-}
+static void (*next_hook_mail_index_transaction_created)
+	(struct mail_index_transaction *t) = NULL;
 
-int dbox_transaction_commit(struct mailbox_transaction_context *_t,
-			    enum mailbox_sync_flags flags __attr_unused__)
+static int dbox_transaction_commit(struct mail_index_transaction *t,
+				   uint32_t *log_file_seq_r,
+				   uoff_t *log_file_offset_r)
 {
-	struct dbox_transaction_context *t =
-		(struct dbox_transaction_context *)_t;
-	struct dbox_mailbox *dbox = (struct dbox_mailbox *)t->ictx.ibox;
+	struct dbox_transaction_context *dt = MAIL_STORAGE_TRANSACTION(t);
+	struct dbox_mailbox *dbox = (struct dbox_mailbox *)dt->ictx.ibox;
 	struct dbox_save_context *save_ctx;
+	bool external = t->external;
 	int ret = 0;
 
-	if (t->save_ctx != NULL) {
-		if (dbox_transaction_save_commit_pre(t->save_ctx) < 0) {
-			t->save_ctx = NULL;
+	if (dt->save_ctx != NULL) {
+		if (dbox_transaction_save_commit_pre(dt->save_ctx) < 0) {
+			dt->save_ctx = NULL;
 			ret = -1;
 		}
 	}
 
-	save_ctx = t->save_ctx;
+	save_ctx = dt->save_ctx;
 
-	if (ret == 0) {
-		if (index_transaction_commit(_t) < 0)
+	if (ret < 0)
+		index_transaction_finish_rollback(&dt->ictx);
+	else {
+		if (index_transaction_finish_commit(&dt->ictx, log_file_seq_r,
+						    log_file_offset_r) < 0)
 			ret = -1;
-	} else {
-		index_transaction_rollback(_t);
 	}
-	/* transaction is destroyed. */
-	t = NULL; _t = NULL;
+
+	/* transaction is destroyed now. */
+	dt = NULL;
 
 	if (save_ctx != NULL) {
 		/* unlock uidlist file after writing to transaction log,
@@ -49,7 +44,7 @@
 		dbox_transaction_save_commit_post(save_ctx);
 	}
 
-	if (ret == 0) {
+	if (ret == 0 && !external) {
 		if (dbox_sync(dbox, FALSE) < 0)
 			ret = -1;
 	}
@@ -57,13 +52,52 @@
 	return ret;
 }
 
-void dbox_transaction_rollback(struct mailbox_transaction_context *_t)
+static void dbox_transaction_rollback(struct mail_index_transaction *t)
 {
-	struct dbox_transaction_context *t =
-		(struct dbox_transaction_context *)_t;
+	struct dbox_transaction_context *dt = MAIL_STORAGE_TRANSACTION(t);
 
-	if (t->save_ctx != NULL)
-		dbox_transaction_save_rollback(t->save_ctx);
+	if (dt->save_ctx != NULL)
+		dbox_transaction_save_rollback(dt->save_ctx);
 
-	index_transaction_rollback(_t);
+	index_transaction_finish_rollback(&dt->ictx);
+}
+
+void dbox_transaction_created(struct mail_index_transaction *t)
+{
+	struct mailbox *box = MAIL_STORAGE_INDEX(t->view->index);
+
+	if (strcmp(box->storage->name, DBOX_STORAGE_NAME) == 0) {
+		struct dbox_mailbox *dbox = (struct dbox_mailbox *)box;
+		struct dbox_transaction_context *mt;
+
+		mt = i_new(struct dbox_transaction_context, 1);
+		mt->ictx.trans = t;
+		mt->ictx.super = t->v;
+
+		t->v.commit = dbox_transaction_commit;
+		t->v.rollback = dbox_transaction_rollback;
+
+		array_idx_set(&t->mail_index_transaction_module_contexts,
+			      mail_storage_mail_index_module_id, &mt);
+
+		index_transaction_init(&mt->ictx, &dbox->ibox);
+	}
+
+	if (next_hook_mail_index_transaction_created != NULL)
+		next_hook_mail_index_transaction_created(t);
+}
+
+void dbox_transaction_class_init(void)
+{
+	next_hook_mail_index_transaction_created =
+		hook_mail_index_transaction_created;
+	hook_mail_index_transaction_created = dbox_transaction_created;
+}
+
+void dbox_transaction_class_deinit(void)
+{
+	i_assert(hook_mail_index_transaction_created ==
+		 dbox_transaction_created);
+	hook_mail_index_transaction_created =
+		next_hook_mail_index_transaction_created;
 }



More information about the dovecot-cvs mailing list