[dovecot-cvs] dovecot/src/lib-storage/index/maildir maildir-storage.c, 1.123, 1.124 maildir-storage.h, 1.52, 1.53 maildir-transaction.c, 1.11, 1.12

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


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

Modified Files:
	maildir-storage.c maildir-storage.h maildir-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: maildir-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.c,v
retrieving revision 1.123
retrieving revision 1.124
diff -u -d -r1.123 -r1.124
--- maildir-storage.c	28 Jun 2006 13:10:52 -0000	1.123
+++ maildir-storage.c	28 Jun 2006 16:31:07 -0000	1.124
@@ -979,11 +979,23 @@
 		t_strconcat(mbox->path, "/cur", NULL));
 }
 
+static void maildir_class_init(void)
+{
+	maildir_transaction_class_init();
+}
+
+static void maildir_class_deinit(void)
+{
+	maildir_transaction_class_deinit();
+}
+
 struct mail_storage maildir_storage = {
-	MEMBER(name) "maildir",
+	MEMBER(name) MAILDIR_STORAGE_NAME,
 	MEMBER(hierarchy_sep) MAILDIR_FS_SEP,
 
 	{
+		maildir_class_init,
+		maildir_class_deinit,
 		maildir_create,
 		maildir_free,
 		maildir_autodetect,
@@ -1016,9 +1028,9 @@
 		index_mailbox_sync_next,
 		index_mailbox_sync_deinit,
 		maildir_notify_changes,
-		maildir_transaction_begin,
-		maildir_transaction_commit,
-		maildir_transaction_rollback,
+		index_transaction_begin,
+		index_transaction_commit,
+		index_transaction_rollback,
 		index_keywords_create,
 		index_keywords_free,
 		index_storage_get_uids,

Index: maildir-storage.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-storage.h,v
retrieving revision 1.52
retrieving revision 1.53
diff -u -d -r1.52 -r1.53
--- maildir-storage.h	28 Jun 2006 13:10:52 -0000	1.52
+++ maildir-storage.h	28 Jun 2006 16:31:07 -0000	1.53
@@ -5,6 +5,7 @@
 #define MAILDIR_FS_SEP '.'
 #define MAILDIR_FS_SEP_S "."
 
+#define MAILDIR_STORAGE_NAME "maildir"
 #define SUBSCRIPTION_FILE_NAME "subscriptions"
 #define MAILDIR_INDEX_PREFIX "dovecot.index"
 #define MAILDIR_UNLINK_DIRNAME MAILDIR_FS_SEP_S"DOVECOT-TRASHED"
@@ -113,12 +114,9 @@
 int maildir_sync_index_finish(struct maildir_index_sync_context **sync_ctx,
 			      bool failed);
 
-struct mailbox_transaction_context *
-maildir_transaction_begin(struct mailbox *box,
-			  enum mailbox_transaction_flags flags);
-int maildir_transaction_commit(struct mailbox_transaction_context *t,
-			       enum mailbox_sync_flags flags);
-void maildir_transaction_rollback(struct mailbox_transaction_context *t);
+void maildir_transaction_created(struct mail_index_transaction *t);
+void maildir_transaction_class_init(void);
+void maildir_transaction_class_deinit(void);
 
 int maildir_save_init(struct mailbox_transaction_context *_t,
 		      enum mail_flags flags, struct mail_keywords *keywords,

Index: maildir-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/maildir/maildir-transaction.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -d -r1.11 -r1.12
--- maildir-transaction.c	6 Mar 2006 18:16:12 -0000	1.11
+++ maildir-transaction.c	28 Jun 2006 16:31:07 -0000	1.12
@@ -1,56 +1,90 @@
 /* Copyright (C) 2004 Timo Sirainen */
 
 #include "lib.h"
+#include "array.h"
 #include "maildir-storage.h"
 
-struct mailbox_transaction_context *
-maildir_transaction_begin(struct mailbox *box,
-			  enum mailbox_transaction_flags flags)
-{
-	struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
-	struct maildir_transaction_context *t;
-
-	t = i_new(struct maildir_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 maildir_transaction_commit(struct mailbox_transaction_context *_t,
-			       enum mailbox_sync_flags flags __attr_unused__)
+static int maildir_transaction_commit(struct mail_index_transaction *t,
+				      uint32_t *log_file_seq_r,
+				      uoff_t *log_file_offset_r)
 {
-	struct maildir_transaction_context *t =
-		(struct maildir_transaction_context *)_t;
-	struct maildir_mailbox *mbox = (struct maildir_mailbox *)t->ictx.ibox;
+	struct maildir_transaction_context *mt = MAIL_STORAGE_TRANSACTION(t);
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)mt->ictx.ibox;
 	struct maildir_save_context *save_ctx;
+	bool external = t->external;
 	int ret = 0;
 
-	if (t->save_ctx != NULL) {
-		if (maildir_transaction_save_commit_pre(t->save_ctx) < 0) {
-			t->save_ctx = NULL;
+	if (mt->save_ctx != NULL) {
+		if (maildir_transaction_save_commit_pre(mt->save_ctx) < 0) {
+			mt->save_ctx = NULL;
 			ret = -1;
 		}
 	}
 
-	save_ctx = t->save_ctx;
+	save_ctx = mt->save_ctx;
 
-	if (index_transaction_commit(_t) < 0)
+	if (index_transaction_finish_commit(&mt->ictx, log_file_seq_r,
+					    log_file_offset_r) < 0)
 		ret = -1;
 
-	/* transaction is destroyed. */
-	t = NULL; _t = NULL;
+	/* transaction is destroyed now. */
+	mt = NULL;
 
 	if (save_ctx != NULL)
 		maildir_transaction_save_commit_post(save_ctx);
 
-	return ret < 0 ? -1 : maildir_sync_last_commit(mbox);
+	if (ret == 0 && !external)
+		ret = maildir_sync_last_commit(mbox);
+	return ret;
 }
 
-void maildir_transaction_rollback(struct mailbox_transaction_context *_t)
+static void maildir_transaction_rollback(struct mail_index_transaction *t)
 {
-	struct maildir_transaction_context *t =
-		(struct maildir_transaction_context *)_t;
+	struct maildir_transaction_context *mt = MAIL_STORAGE_TRANSACTION(t);
 
-	if (t->save_ctx != NULL)
-		maildir_transaction_save_rollback(t->save_ctx);
-	index_transaction_rollback(_t);
+	if (mt->save_ctx != NULL)
+		maildir_transaction_save_rollback(mt->save_ctx);
+	index_transaction_finish_rollback(&mt->ictx);
+}
+
+void maildir_transaction_created(struct mail_index_transaction *t)
+{
+	struct mailbox *box = MAIL_STORAGE_INDEX(t->view->index);
+
+	if (strcmp(box->storage->name, MAILDIR_STORAGE_NAME) == 0) {
+		struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
+		struct maildir_transaction_context *mt;
+
+		mt = i_new(struct maildir_transaction_context, 1);
+		mt->ictx.trans = t;
+		mt->ictx.super = t->v;
+
+		t->v.commit = maildir_transaction_commit;
+		t->v.rollback = maildir_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 maildir_transaction_class_init(void)
+{
+	next_hook_mail_index_transaction_created =
+		hook_mail_index_transaction_created;
+	hook_mail_index_transaction_created = maildir_transaction_created;
+}
+
+void maildir_transaction_class_deinit(void)
+{
+	i_assert(hook_mail_index_transaction_created ==
+		 maildir_transaction_created);
+	hook_mail_index_transaction_created =
+		next_hook_mail_index_transaction_created;
 }



More information about the dovecot-cvs mailing list