From e03d986a74128f5ba30fcfda9f6e36578f5d8dec Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Mon, 15 Feb 2010 02:54:32 +0200 Subject: [PATCH] lib-storage: Added mailbox.free() method. Use it instead of close() where necessary. --HG-- branch : HEAD --- src/lib-storage/index/cydir/cydir-storage.c | 1 + src/lib-storage/index/dbox-multi/mdbox-storage.c | 1 + .../index/dbox-single/sdbox-storage.c | 1 + src/lib-storage/index/index-storage.c | 3 ++- src/lib-storage/index/index-thread-private.h | 2 +- src/lib-storage/index/index-thread.c | 16 ++++++++++++---- src/lib-storage/index/maildir/maildir-storage.c | 6 ++++-- src/lib-storage/index/mbox/mbox-storage.c | 1 + src/lib-storage/index/raw/raw-storage.c | 1 + src/lib-storage/mail-storage-private.h | 1 + src/lib-storage/mail-storage.c | 3 +++ src/lib-storage/test-mailbox.c | 1 + src/plugins/acl/acl-mailbox.c | 6 +++--- src/plugins/fts/fts-storage.c | 6 +++--- src/plugins/quota/quota-storage.c | 6 +++--- src/plugins/virtual/virtual-storage.c | 1 + 16 files changed, 39 insertions(+), 17 deletions(-) diff --git a/src/lib-storage/index/cydir/cydir-storage.c b/src/lib-storage/index/cydir/cydir-storage.c index 367f41684e..6912de7284 100644 --- a/src/lib-storage/index/cydir/cydir-storage.c +++ b/src/lib-storage/index/cydir/cydir-storage.c @@ -140,6 +140,7 @@ struct mailbox cydir_mailbox = { index_storage_mailbox_enable, cydir_mailbox_open, index_storage_mailbox_close, + NULL, cydir_mailbox_create, index_storage_mailbox_update, index_storage_mailbox_delete, diff --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index 8a13635635..ed6692106b 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -327,6 +327,7 @@ struct mailbox mdbox_mailbox = { index_storage_mailbox_enable, dbox_mailbox_open, index_storage_mailbox_close, + NULL, dbox_mailbox_create, mdbox_mailbox_update, mdbox_mailbox_delete, diff --git a/src/lib-storage/index/dbox-single/sdbox-storage.c b/src/lib-storage/index/dbox-single/sdbox-storage.c index 4ea1a896b7..217f22cde8 100644 --- a/src/lib-storage/index/dbox-single/sdbox-storage.c +++ b/src/lib-storage/index/dbox-single/sdbox-storage.c @@ -217,6 +217,7 @@ struct mailbox sdbox_mailbox = { index_storage_mailbox_enable, dbox_mailbox_open, index_storage_mailbox_close, + NULL, dbox_mailbox_create, dbox_mailbox_update, index_storage_mailbox_delete, diff --git a/src/lib-storage/index/index-storage.c b/src/lib-storage/index/index-storage.c index 29a3edc4dd..a83da96540 100644 --- a/src/lib-storage/index/index-storage.c +++ b/src/lib-storage/index/index-storage.c @@ -243,7 +243,6 @@ int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory) box->opened = TRUE; - index_thread_mailbox_opened(box); if (hook_mailbox_opened != NULL) hook_mailbox_opened(box); @@ -291,6 +290,8 @@ void index_storage_mailbox_alloc(struct mailbox *box, const char *name, mail_index_set_permissions(box->index, box->file_create_mode, box->file_create_gid, box->file_create_gid_origin); + + index_thread_mailbox_allocated(box); } int index_storage_mailbox_enable(struct mailbox *box, diff --git a/src/lib-storage/index/index-thread-private.h b/src/lib-storage/index/index-thread-private.h index 4f44319188..5b33ad36fa 100644 --- a/src/lib-storage/index/index-thread-private.h +++ b/src/lib-storage/index/index-thread-private.h @@ -77,6 +77,6 @@ mail_thread_iterate_init_full(struct mail_thread_cache *cache, enum mail_thread_type thread_type, bool return_seqs); -void index_thread_mailbox_opened(struct mailbox *box); +void index_thread_mailbox_allocated(struct mailbox *box); #endif diff --git a/src/lib-storage/index/index-thread.c b/src/lib-storage/index/index-thread.c index 991421cffa..9df8598696 100644 --- a/src/lib-storage/index/index-thread.c +++ b/src/lib-storage/index/index-thread.c @@ -622,23 +622,31 @@ static void mail_thread_mailbox_close(struct mailbox *box) if (tbox->strmap_view != NULL) mail_index_strmap_view_close(&tbox->strmap_view); - mail_index_strmap_deinit(&tbox->strmap); if (tbox->cache->search_result != NULL) mailbox_search_result_free(&tbox->cache->search_result); + tbox->module_ctx.super.close(box); +} + +static void mail_thread_mailbox_free(struct mailbox *box) +{ + struct mail_thread_mailbox *tbox = MAIL_THREAD_CONTEXT(box); + + mail_index_strmap_deinit(&tbox->strmap); + tbox->module_ctx.super.free(box); + array_free(&tbox->cache->thread_nodes); i_free(tbox->cache); - - tbox->module_ctx.super.close(box); i_free(tbox); } -void index_thread_mailbox_opened(struct mailbox *box) +void index_thread_mailbox_allocated(struct mailbox *box) { struct mail_thread_mailbox *tbox; tbox = i_new(struct mail_thread_mailbox, 1); tbox->module_ctx.super = box->v; box->v.close = mail_thread_mailbox_close; + box->v.free = mail_thread_mailbox_free; tbox->strmap = mail_index_strmap_init(box->index, MAIL_THREAD_INDEX_SUFFIX); diff --git a/src/lib-storage/index/maildir/maildir-storage.c b/src/lib-storage/index/maildir/maildir-storage.c index cfa9d2261e..a093fd5792 100644 --- a/src/lib-storage/index/maildir/maildir-storage.c +++ b/src/lib-storage/index/maildir/maildir-storage.c @@ -290,8 +290,6 @@ maildir_mailbox_alloc(struct mail_storage *storage, struct mailbox_list *list, mbox->maildir_ext_id = mail_index_ext_register(mbox->box.index, "maildir", sizeof(mbox->maildir_hdr), 0, 0); - mbox->uidlist = maildir_uidlist_init(mbox); - mbox->keywords = maildir_keywords_init(mbox); return &mbox->box; } @@ -301,6 +299,9 @@ static int maildir_mailbox_open_existing(struct mailbox *box) struct stat st; const char *shared_path; + mbox->uidlist = maildir_uidlist_init(mbox); + mbox->keywords = maildir_keywords_init(mbox); + shared_path = t_strconcat(box->path, "/dovecot-shared", NULL); if (stat(shared_path, &st) == 0) box->private_flags_mask = MAIL_SEEN; @@ -578,6 +579,7 @@ struct mailbox maildir_mailbox = { index_storage_mailbox_enable, maildir_mailbox_open, maildir_mailbox_close, + NULL, maildir_mailbox_create, maildir_mailbox_update, index_storage_mailbox_delete, diff --git a/src/lib-storage/index/mbox/mbox-storage.c b/src/lib-storage/index/mbox/mbox-storage.c index 6e9adf6c03..37e43fee2c 100644 --- a/src/lib-storage/index/mbox/mbox-storage.c +++ b/src/lib-storage/index/mbox/mbox-storage.c @@ -693,6 +693,7 @@ struct mailbox mbox_mailbox = { index_storage_mailbox_enable, mbox_mailbox_open, mbox_mailbox_close, + NULL, mbox_mailbox_create, mbox_mailbox_update, index_storage_mailbox_delete, diff --git a/src/lib-storage/index/raw/raw-storage.c b/src/lib-storage/index/raw/raw-storage.c index 101ca45cbb..28f842e38a 100644 --- a/src/lib-storage/index/raw/raw-storage.c +++ b/src/lib-storage/index/raw/raw-storage.c @@ -134,6 +134,7 @@ struct mailbox raw_mailbox = { index_storage_mailbox_enable, raw_mailbox_open, index_storage_mailbox_close, + NULL, raw_mailbox_create, raw_mailbox_update, index_storage_mailbox_delete, diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 93961d2f83..112c968565 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -93,6 +93,7 @@ struct mailbox_vfuncs { int (*enable)(struct mailbox *box, enum mailbox_feature features); int (*open)(struct mailbox *box); void (*close)(struct mailbox *box); + void (*free)(struct mailbox *box); int (*create)(struct mailbox *box, const struct mailbox_update *update, bool directory); diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index aaf9e2ad19..72be02ccea 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -580,6 +580,9 @@ void mailbox_free(struct mailbox **_box) *_box = NULL; mailbox_close(box); + + if (box->v.free != NULL) + box->v.free(box); mail_index_alloc_cache_unref(&box->index); pool_unref(&box->pool); } diff --git a/src/lib-storage/test-mailbox.c b/src/lib-storage/test-mailbox.c index cd1bfe0e68..1da2e57037 100644 --- a/src/lib-storage/test-mailbox.c +++ b/src/lib-storage/test-mailbox.c @@ -322,6 +322,7 @@ struct mailbox test_mailbox = { test_mailbox_enable, test_mailbox_open, test_mailbox_close, + NULL, test_mailbox_create, test_mailbox_update, test_mailbox_delete, diff --git a/src/plugins/acl/acl-mailbox.c b/src/plugins/acl/acl-mailbox.c index 81ab8ed4ee..c70af184bb 100644 --- a/src/plugins/acl/acl-mailbox.c +++ b/src/plugins/acl/acl-mailbox.c @@ -97,12 +97,12 @@ static bool acl_allow_new_keywords(struct mailbox *box) return acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE) > 0; } -static void acl_mailbox_close(struct mailbox *box) +static void acl_mailbox_free(struct mailbox *box) { struct acl_mailbox *abox = ACL_CONTEXT(box); acl_object_deinit(&abox->aclobj); - abox->module_ctx.super.close(box); + abox->module_ctx.super.free(box); } static void acl_mailbox_copy_acls_from_parent(struct mailbox *box) @@ -518,7 +518,7 @@ void acl_mailbox_allocated(struct mailbox *box) box->v.is_readonly = acl_is_readonly; box->v.allow_new_keywords = acl_allow_new_keywords; box->v.open = acl_mailbox_open; - box->v.close = acl_mailbox_close; + box->v.free = acl_mailbox_free; box->v.create = acl_mailbox_create; box->v.update = acl_mailbox_update; box->v.delete = acl_mailbox_delete; diff --git a/src/plugins/fts/fts-storage.c b/src/plugins/fts/fts-storage.c index d3b2351c19..5ed941c580 100644 --- a/src/plugins/fts/fts-storage.c +++ b/src/plugins/fts/fts-storage.c @@ -59,7 +59,7 @@ static MODULE_CONTEXT_DEFINE_INIT(fts_storage_module, &mail_storage_module_register); static MODULE_CONTEXT_DEFINE_INIT(fts_mail_module, &mail_module_register); -static void fts_mailbox_close(struct mailbox *box) +static void fts_mailbox_free(struct mailbox *box) { struct fts_mailbox *fbox = FTS_CONTEXT(box); @@ -68,7 +68,7 @@ static void fts_mailbox_close(struct mailbox *box) if (fbox->backend_fast != NULL) fts_backend_deinit(&fbox->backend_fast); - fbox->module_ctx.super.close(box); + fbox->module_ctx.super.free(box); i_free(fbox); } @@ -1028,7 +1028,7 @@ static void fts_mailbox_init(struct mailbox *box, const char *env) fbox->virtual = strcmp(box->storage->name, "virtual") == 0; fbox->env = env; fbox->module_ctx.super = box->v; - box->v.close = fts_mailbox_close; + box->v.free = fts_mailbox_free; box->v.search_init = fts_mailbox_search_init; box->v.search_next_nonblock = fts_mailbox_search_next_nonblock; box->v.search_next_update_seq = fbox->virtual ? diff --git a/src/plugins/quota/quota-storage.c b/src/plugins/quota/quota-storage.c index 738491a38b..8ca52af123 100644 --- a/src/plugins/quota/quota-storage.c +++ b/src/plugins/quota/quota-storage.c @@ -373,7 +373,7 @@ static int quota_mailbox_delete(struct mailbox *box) return qbox->module_ctx.super.delete(box); } -static void quota_mailbox_close(struct mailbox *box) +static void quota_mailbox_free(struct mailbox *box) { struct quota_mailbox *qbox = QUOTA_CONTEXT(box); @@ -384,7 +384,7 @@ static void quota_mailbox_close(struct mailbox *box) i_assert(qbox->expunge_qt == NULL || qbox->expunge_qt->tmp_mail == NULL); - qbox->module_ctx.super.close(box); + qbox->module_ctx.super.free(box); } void quota_mailbox_allocated(struct mailbox *box) @@ -407,7 +407,7 @@ void quota_mailbox_allocated(struct mailbox *box) box->v.sync_notify = quota_mailbox_sync_notify; box->v.sync_deinit = quota_mailbox_sync_deinit; box->v.delete = quota_mailbox_delete; - box->v.close = quota_mailbox_close; + box->v.free = quota_mailbox_free; MODULE_CONTEXT_SET(box, quota_storage_module, qbox); } diff --git a/src/plugins/virtual/virtual-storage.c b/src/plugins/virtual/virtual-storage.c index 60a92b5c49..397095ab22 100644 --- a/src/plugins/virtual/virtual-storage.c +++ b/src/plugins/virtual/virtual-storage.c @@ -445,6 +445,7 @@ struct mailbox virtual_mailbox = { index_storage_mailbox_enable, virtual_mailbox_open, virtual_mailbox_close, + NULL, virtual_mailbox_create, virtual_mailbox_update, index_storage_mailbox_delete, -- 2.47.3