dovecot-2.2: lib-storage: Moved mail attribute dict to struct ma...

dovecot at dovecot.org dovecot at dovecot.org
Mon Oct 29 14:51:04 EET 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/ca10d2e8d8e3
changeset: 15272:ca10d2e8d8e3
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Oct 29 14:50:11 2012 +0200
description:
lib-storage: Moved mail attribute dict to struct mail_storage.
This also means that index_storage_destroy() must always be called, so
removed now unnecessary mail_storage.destroy=NULL checks.

diffstat:

 src/lib-storage/index/cydir/cydir-storage.c        |   2 +-
 src/lib-storage/index/dbox-common/dbox-storage.c   |   1 +
 src/lib-storage/index/imapc/imapc-storage.c        |   1 +
 src/lib-storage/index/index-attribute.c            |  35 ++++++++++-----------
 src/lib-storage/index/index-storage.c              |  12 +++++--
 src/lib-storage/index/index-storage.h              |   1 +
 src/lib-storage/index/maildir/maildir-storage.c    |   2 +-
 src/lib-storage/index/mbox/mbox-storage.c          |   2 +-
 src/lib-storage/index/pop3c/pop3c-storage.c        |   2 +-
 src/lib-storage/index/raw/raw-storage.c            |   2 +-
 src/lib-storage/index/shared/shared-storage.c      |   2 +-
 src/lib-storage/mail-storage-private.h             |   9 +++--
 src/lib-storage/mail-storage.c                     |   3 +-
 src/plugins/pop3-migration/pop3-migration-plugin.c |   3 +-
 src/plugins/virtual/virtual-storage.c              |   2 +-
 15 files changed, 42 insertions(+), 37 deletions(-)

diffs (285 lines):

diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/cydir/cydir-storage.c
--- a/src/lib-storage/index/cydir/cydir-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/cydir/cydir-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -117,7 +117,7 @@
 		NULL,
 		cydir_storage_alloc,
 		NULL,
-		NULL,
+		index_storage_destroy,
 		NULL,
 		cydir_storage_get_list_settings,
 		NULL,
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/dbox-common/dbox-storage.c
--- a/src/lib-storage/index/dbox-common/dbox-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -122,6 +122,7 @@
 
 	if (storage->attachment_fs != NULL)
 		fs_deinit(&storage->attachment_fs);
+	index_storage_destroy(_storage);
 }
 
 uint32_t dbox_get_uidvalidity_next(struct mailbox_list *list)
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/imapc/imapc-storage.c
--- a/src/lib-storage/index/imapc/imapc-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/imapc/imapc-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -276,6 +276,7 @@
 	struct imapc_storage *storage = (struct imapc_storage *)_storage;
 
 	imapc_client_deinit(&storage->client);
+	index_storage_destroy(_storage);
 }
 
 static void imapc_storage_add_list(struct mail_storage *_storage,
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/index-attribute.c
--- a/src/lib-storage/index/index-attribute.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/index-attribute.c	Mon Oct 29 14:50:11 2012 +0200
@@ -4,9 +4,6 @@
 #include "dict.h"
 #include "index-storage.h"
 
-#define KEY_PREFIX_PRIVATE "priv/"
-#define KEY_PREFIX_SHARED "shared/"
-
 struct index_storage_attribute_iter {
 	struct mailbox_attribute_iter iter;
 	struct dict_iterate_context *diter;
@@ -18,6 +15,7 @@
 static int index_storage_get_dict(struct mailbox *box, struct dict **dict_r,
 				  const char **mailbox_prefix_r)
 {
+	struct mail_storage *storage = box->storage;
 	struct mailbox_metadata metadata;
 	const char *error;
 
@@ -25,31 +23,32 @@
 		return -1;
 	*mailbox_prefix_r = guid_128_to_string(metadata.guid);
 
-	if (box->_attr_dict != NULL) {
-		*dict_r = box->_attr_dict;
+	if (storage->_attr_dict != NULL) {
+		*dict_r = storage->_attr_dict;
 		return 0;
 	}
-	if (*box->storage->set->mail_attribute_dict == '\0') {
-		mail_storage_set_error(box->storage, MAIL_ERROR_NOTPOSSIBLE,
+	if (*storage->set->mail_attribute_dict == '\0') {
+		mail_storage_set_error(storage, MAIL_ERROR_NOTPOSSIBLE,
 				       "Mailbox attributes not enabled");
 		return -1;
 	}
-	if (box->attr_dict_failed) {
-		mail_storage_set_internal_error(box->storage);
+	if (storage->attr_dict_failed) {
+		mail_storage_set_internal_error(storage);
 		return -1;
 	}
 
-	if (dict_init(box->storage->set->mail_attribute_dict,
+	if (dict_init(storage->set->mail_attribute_dict,
 		      DICT_DATA_TYPE_STRING,
-		      box->storage->user->username,
-		      box->storage->user->set->base_dir,
-		      &box->_attr_dict, &error) < 0) {
-		mail_storage_set_critical(box->storage,
+		      storage->user->username,
+		      storage->user->set->base_dir,
+		      &storage->_attr_dict, &error) < 0) {
+		mail_storage_set_critical(storage,
 			"mail_attribute_dict: dict_init(%s) failed: %s",
-			box->storage->set->mail_attribute_dict, error);
+			storage->set->mail_attribute_dict, error);
+		storage->attr_dict_failed = TRUE;
 		return -1;
 	}
-	*dict_r = box->_attr_dict;
+	*dict_r = storage->_attr_dict;
 	return 0;
 }
 
@@ -59,10 +58,10 @@
 {
 	switch (type) {
 	case MAIL_ATTRIBUTE_TYPE_PRIVATE:
-		return t_strconcat(KEY_PREFIX_PRIVATE, mailbox_prefix, "/",
+		return t_strconcat(DICT_PATH_PRIVATE, mailbox_prefix, "/",
 				   key, NULL);
 	case MAIL_ATTRIBUTE_TYPE_SHARED:
-		return t_strconcat(KEY_PREFIX_SHARED, mailbox_prefix, "/",
+		return t_strconcat(DICT_PATH_SHARED, mailbox_prefix, "/",
 				   key, NULL);
 	}
 	i_unreached();
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/index-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -360,10 +360,6 @@
 
 void index_storage_mailbox_free(struct mailbox *box)
 {
-	if (box->_attr_dict != NULL) {
-		(void)dict_wait(box->_attr_dict);
-		dict_deinit(&box->_attr_dict);
-	}
 	if (box->index_pvt != NULL)
 		mail_index_alloc_cache_unref(&box->index_pvt);
 	if (box->index != NULL)
@@ -808,3 +804,11 @@
 	}
 	return 0;
 }
+
+void index_storage_destroy(struct mail_storage *storage)
+{
+	if (storage->_attr_dict != NULL) {
+		(void)dict_wait(storage->_attr_dict);
+		dict_deinit(&storage->_attr_dict);
+	}
+}
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/index-storage.h
--- a/src/lib-storage/index/index-storage.h	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/index-storage.h	Mon Oct 29 14:50:11 2012 +0200
@@ -155,6 +155,7 @@
 void index_copy_cache_fields(struct mail_save_context *ctx,
 			     struct mail *src_mail, uint32_t dest_seq);
 int index_storage_set_subscribed(struct mailbox *box, bool set);
+void index_storage_destroy(struct mail_storage *storage);
 
 bool index_keyword_array_cmp(const ARRAY_TYPE(keyword_indexes) *k1,
 			     const ARRAY_TYPE(keyword_indexes) *k2);
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/maildir/maildir-storage.c
--- a/src/lib-storage/index/maildir/maildir-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -657,7 +657,7 @@
                 maildir_get_setting_parser_info,
 		maildir_storage_alloc,
 		maildir_storage_create,
-		NULL,
+		index_storage_destroy,
 		maildir_storage_add_list,
 		maildir_storage_get_list_settings,
 		maildir_storage_autodetect,
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/mbox/mbox-storage.c
--- a/src/lib-storage/index/mbox/mbox-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -793,7 +793,7 @@
                 mbox_get_setting_parser_info,
 		mbox_storage_alloc,
 		mbox_storage_create,
-		NULL,
+		index_storage_destroy,
 		mbox_storage_add_list,
 		mbox_storage_get_list_settings,
 		mbox_storage_autodetect,
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/pop3c/pop3c-storage.c
--- a/src/lib-storage/index/pop3c/pop3c-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/pop3c/pop3c-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -226,7 +226,7 @@
 		pop3c_get_setting_parser_info,
 		pop3c_storage_alloc,
 		pop3c_storage_create,
-		NULL,
+		index_storage_destroy,
 		NULL,
 		pop3c_storage_get_list_settings,
 		NULL,
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/raw/raw-storage.c
--- a/src/lib-storage/index/raw/raw-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/raw/raw-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -199,7 +199,7 @@
 		NULL,
 		raw_storage_alloc,
 		NULL,
-		NULL,
+		index_storage_destroy,
 		NULL,
 		raw_storage_get_list_settings,
 		NULL,
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/index/shared/shared-storage.c
--- a/src/lib-storage/index/shared/shared-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/index/shared/shared-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -351,7 +351,7 @@
 		NULL,
 		shared_storage_alloc,
 		shared_storage_create,
-		NULL,
+		index_storage_destroy,
 		NULL,
 		shared_storage_get_list_settings,
 		NULL,
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/mail-storage-private.h
--- a/src/lib-storage/mail-storage-private.h	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/mail-storage-private.h	Mon Oct 29 14:50:11 2012 +0200
@@ -108,9 +108,14 @@
 	void *callback_context;
 
 	struct mail_binary_cache binary_cache;
+	/* Filled lazily by mailbox_attribute_*() */
+	struct dict *_attr_dict;
 
 	/* Module-specific contexts. See mail_storage_module_id. */
 	ARRAY(union mail_storage_module_context *) module_contexts;
+
+	/* Failed to create attribute dict, don't try again */
+	unsigned int attr_dict_failed:1;
 };
 
 struct mail_attachment_part {
@@ -261,8 +266,6 @@
 	/* Filled lazily when mailbox is opened, use mailbox_get_path()
 	   to access it */
 	const char *_path;
-	/* Filled lazily by mailbox_attribute_*() */
-	struct dict *_attr_dict;
 
 	/* default vfuncs for new struct mails. */
 	const struct mail_vfuncs *mail_vfuncs;
@@ -320,8 +323,6 @@
 	unsigned int disallow_new_keywords:1;
 	/* Mailbox has been synced at least once */
 	unsigned int synced:1;
-	/* Failed to create attribute dict, don't try again */
-	unsigned int attr_dict_failed:1;
 };
 
 struct mail_vfuncs {
diff -r 0f16da39121a -r ca10d2e8d8e3 src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/lib-storage/mail-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -413,8 +413,7 @@
 
 	DLLIST_REMOVE(&storage->user->storages, storage);
 
-	if (storage->v.destroy != NULL)
-		storage->v.destroy(storage);
+	storage->v.destroy(storage);
 	i_free(storage->error_string);
 
 	*_storage = NULL;
diff -r 0f16da39121a -r ca10d2e8d8e3 src/plugins/pop3-migration/pop3-migration-plugin.c
--- a/src/plugins/pop3-migration/pop3-migration-plugin.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/plugins/pop3-migration/pop3-migration-plugin.c	Mon Oct 29 14:50:11 2012 +0200
@@ -595,8 +595,7 @@
 	if (array_is_created(&mstorage->pop3_uidl_map))
 		array_free(&mstorage->pop3_uidl_map);
 
-	if (mstorage->module_ctx.super.destroy != NULL)
-		mstorage->module_ctx.super.destroy(storage);
+	mstorage->module_ctx.super.destroy(storage);
 }
 
 static void pop3_migration_mail_storage_created(struct mail_storage *storage)
diff -r 0f16da39121a -r ca10d2e8d8e3 src/plugins/virtual/virtual-storage.c
--- a/src/plugins/virtual/virtual-storage.c	Mon Oct 29 14:31:04 2012 +0200
+++ b/src/plugins/virtual/virtual-storage.c	Mon Oct 29 14:50:11 2012 +0200
@@ -503,7 +503,7 @@
 		NULL,
 		virtual_storage_alloc,
 		NULL,
-		NULL,
+		index_storage_destroy,
 		NULL,
 		virtual_storage_get_list_settings,
 		NULL,


More information about the dovecot-cvs mailing list