Mercurial > dovecot > core-2.2
changeset 12659:c65dc5f520f8
lib-storage: layout=fs now uses mailbox_exists() instead of requiring storage hooks.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sat, 12 Feb 2011 05:17:12 +0200 |
parents | 078419bc739a |
children | 43edb481978f |
files | src/lib-storage/index/index-storage.c src/lib-storage/index/index-storage.h src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/list/mailbox-list-fs-iter.c src/plugins/virtual/virtual-storage.c |
diffstat | 5 files changed, 50 insertions(+), 93 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/index/index-storage.c Sat Feb 12 05:12:36 2011 +0200 +++ b/src/lib-storage/index/index-storage.c Sat Feb 12 05:17:12 2011 +0200 @@ -153,6 +153,12 @@ int index_storage_mailbox_exists(struct mailbox *box, enum mailbox_existence *existence_r) { + return index_storage_mailbox_exists_full(box, NULL, existence_r); +} + +int index_storage_mailbox_exists_full(struct mailbox *box, const char *subdir, + enum mailbox_existence *existence_r) +{ struct stat st; const char *path, *path2; @@ -166,6 +172,8 @@ /* see if it's selectable */ path = mailbox_list_get_path(box->list, box->name, MAILBOX_LIST_PATH_TYPE_MAILBOX); + if (subdir != NULL) + path = t_strconcat(path, "/", subdir, NULL); if (stat(path, &st) == 0) { *existence_r = MAILBOX_EXISTENCE_SELECT; return 0;
--- a/src/lib-storage/index/index-storage.h Sat Feb 12 05:12:36 2011 +0200 +++ b/src/lib-storage/index/index-storage.h Sat Feb 12 05:17:12 2011 +0200 @@ -65,6 +65,8 @@ const char *index_prefix); int index_storage_mailbox_exists(struct mailbox *box, enum mailbox_existence *existence_r); +int index_storage_mailbox_exists_full(struct mailbox *box, const char *subdir, + enum mailbox_existence *existence_r); int index_storage_mailbox_open(struct mailbox *box, bool move_to_memory); int index_storage_mailbox_enable(struct mailbox *box, enum mailbox_feature feature);
--- a/src/lib-storage/index/maildir/maildir-storage.c Sat Feb 12 05:12:36 2011 +0200 +++ b/src/lib-storage/index/maildir/maildir-storage.c Sat Feb 12 05:17:12 2011 +0200 @@ -329,6 +329,12 @@ return FALSE; } +static int maildir_mailbox_exists(struct mailbox *box, + enum mailbox_existence *existence_r) +{ + return index_storage_mailbox_exists_full(box, "cur", existence_r); +} + static int maildir_mailbox_open(struct mailbox *box) { const char *box_path = mailbox_get_path(box); @@ -528,46 +534,6 @@ strcmp(name, "tmp") == 0; } -static int -maildir_list_get_mailbox_flags(struct mailbox_list *list, - const char *dir, const char *fname, - enum mailbox_list_file_type type, - struct stat *st_r, - enum mailbox_info_flags *flags) -{ - struct maildir_mailbox_list_context *mlist = MAILDIR_LIST_CONTEXT(list); - struct stat st2; - const char *cur_path; - int ret; - - ret = mlist->module_ctx.super. - get_mailbox_flags(list, dir, fname, type, st_r, flags); - if (ret <= 0 || MAILBOX_INFO_FLAGS_FINISHED(*flags)) - return ret; - - /* see if it's a selectable mailbox. after that we can figure out based - on the link count if we have child mailboxes or not. for a - selectable mailbox we have 3 more links (cur/, new/ and tmp/) - than non-selectable. */ - cur_path = t_strconcat(dir, "/", fname, "/cur", NULL); - if ((ret = stat(cur_path, &st2)) < 0 || !S_ISDIR(st2.st_mode)) { - if (ret < 0 && errno == ENOENT) - *flags |= MAILBOX_NONEXISTENT; - else - *flags |= MAILBOX_NOSELECT; - if (st_r->st_nlink > 2) - *flags |= MAILBOX_CHILDREN; - else - *flags |= MAILBOX_NOCHILDREN; - } else { - if (st_r->st_nlink > 5) - *flags |= MAILBOX_CHILDREN; - else - *flags |= MAILBOX_NOCHILDREN; - } - return 1; -} - static void maildir_storage_add_list(struct mail_storage *storage, struct mailbox_list *list) { @@ -578,7 +544,6 @@ mlist->set = mail_storage_get_driver_settings(storage); list->v.is_internal_name = maildir_is_internal_name; - list->v.get_mailbox_flags = maildir_list_get_mailbox_flags; MODULE_CONTEXT_SET(list, maildir_mailbox_list_module, mlist); } @@ -653,7 +618,7 @@ maildir_storage_is_readonly, index_storage_allow_new_keywords, index_storage_mailbox_enable, - index_storage_mailbox_exists, + maildir_mailbox_exists, maildir_mailbox_open, maildir_mailbox_close, index_storage_mailbox_free,
--- a/src/lib-storage/list/mailbox-list-fs-iter.c Sat Feb 12 05:12:36 2011 +0200 +++ b/src/lib-storage/list/mailbox-list-fs-iter.c Sat Feb 12 05:17:12 2011 +0200 @@ -3,6 +3,7 @@ #include "lib.h" #include "array.h" #include "imap-match.h" +#include "mail-storage.h" #include "mailbox-tree.h" #include "mailbox-list-subscriptions.h" #include "mailbox-list-fs.h" @@ -559,6 +560,29 @@ if (ret <= 0) return ret; + if (!MAILBOX_INFO_FLAGS_FINISHED(ctx->info.flags)) { + struct mailbox *box; + enum mailbox_existence existence; + + box = mailbox_alloc(ctx->ctx.list, list_path, + MAILBOX_FLAG_KEEP_RECENT); + ret = mailbox_exists(box, &existence); + mailbox_free(&box); + + if (ret < 0) + return -1; + switch (existence) { + case MAILBOX_EXISTENCE_NONE: + ctx->info.flags |= MAILBOX_NONEXISTENT; + break; + case MAILBOX_EXISTENCE_NOSELECT: + ctx->info.flags |= MAILBOX_NOSELECT; + break; + case MAILBOX_EXISTENCE_SELECT: + break; + } + } + if (ctx->dir->delayed_send) { /* send the parent directory first, then handle this file again if needed */
--- a/src/plugins/virtual/virtual-storage.c Sat Feb 12 05:12:36 2011 +0200 +++ b/src/plugins/virtual/virtual-storage.c Sat Feb 12 05:17:12 2011 +0200 @@ -20,21 +20,12 @@ #include <dirent.h> #include <sys/stat.h> -#define VIRTUAL_LIST_CONTEXT(obj) \ - MODULE_CONTEXT(obj, virtual_mailbox_list_module) - -struct virtual_mailbox_list { - union mailbox_list_module_context module_ctx; -}; - extern struct mail_storage virtual_storage; extern struct mailbox virtual_mailbox; extern struct virtual_mailbox_vfuncs virtual_mailbox_vfuncs; struct virtual_storage_module virtual_storage_module = MODULE_CONTEXT_INIT(&mail_storage_module_register); -static MODULE_CONTEXT_DEFINE_INIT(virtual_mailbox_list_module, - &mailbox_list_module_register); static bool ns_is_visible(struct mail_namespace *ns) { @@ -273,6 +264,13 @@ i_free_and_null(mbox->vseq_lookup_prev_mailbox); } +static int virtual_mailbox_exists(struct mailbox *box, + enum mailbox_existence *existence_r) +{ + return index_storage_mailbox_exists_full(box, VIRTUAL_CONFIG_FNAME, + existence_r); +} + static int virtual_mailbox_open(struct mailbox *box) { struct virtual_mailbox *mbox = (struct virtual_mailbox *)box; @@ -372,46 +370,6 @@ } } -static int -virtual_list_get_mailbox_flags(struct mailbox_list *list, - const char *dir, const char *fname, - enum mailbox_list_file_type type, - struct stat *st_r, - enum mailbox_info_flags *flags) -{ - struct virtual_mailbox_list *mlist = VIRTUAL_LIST_CONTEXT(list); - struct stat st2; - const char *virtual_path; - int ret; - - ret = mlist->module_ctx.super. - get_mailbox_flags(list, dir, fname, type, st_r, flags); - if (ret <= 0 || MAILBOX_INFO_FLAGS_FINISHED(*flags)) - return ret; - - /* see if it's a selectable mailbox */ - virtual_path = t_strconcat(dir, "/", fname, "/"VIRTUAL_CONFIG_FNAME, - NULL); - if (stat(virtual_path, &st2) < 0) - *flags |= MAILBOX_NOSELECT; - return ret; -} - -static void virtual_storage_add_list(struct mail_storage *storage ATTR_UNUSED, - struct mailbox_list *list) -{ - struct mailbox_list_vfuncs *v = list->vlast; - struct virtual_mailbox_list *mlist; - - mlist = p_new(list->pool, struct virtual_mailbox_list, 1); - mlist->module_ctx.super = *v; - list->vlast = &mlist->module_ctx.super; - - v->get_mailbox_flags = virtual_list_get_mailbox_flags; - - MODULE_CONTEXT_SET(list, virtual_mailbox_list_module, mlist); -} - static int virtual_backend_uidmap_cmp(const uint32_t *uid, const struct virtual_backend_uidmap *map) { @@ -500,7 +458,7 @@ virtual_storage_alloc, NULL, NULL, - virtual_storage_add_list, + NULL, virtual_storage_get_list_settings, NULL, virtual_mailbox_alloc, @@ -513,7 +471,7 @@ index_storage_is_readonly, index_storage_allow_new_keywords, index_storage_mailbox_enable, - index_storage_mailbox_exists, + virtual_mailbox_exists, virtual_mailbox_open, virtual_mailbox_close, virtual_mailbox_free,