dovecot-1.2: When autocreating a new shared namespace, drop exis...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Nov 19 18:57:48 EET 2008
details: http://hg.dovecot.org/dovecot-1.2/rev/4cf249042df6
changeset: 8448:4cf249042df6
user: Timo Sirainen <tss at iki.fi>
date: Wed Nov 19 18:57:43 2008 +0200
description:
When autocreating a new shared namespace, drop existing namespaces where we haven't seen any mailboxes.
diffstat:
3 files changed, 27 insertions(+), 4 deletions(-)
src/lib-storage/index/shared/shared-storage.c | 19 +++++++++++++++++--
src/lib-storage/mail-namespace.h | 5 ++++-
src/lib-storage/mailbox-list.c | 7 ++++++-
diffs (75 lines):
diff -r c56835b33b14 -r 4cf249042df6 src/lib-storage/index/shared/shared-storage.c
--- a/src/lib-storage/index/shared/shared-storage.c Wed Nov 19 18:46:25 2008 +0200
+++ b/src/lib-storage/index/shared/shared-storage.c Wed Nov 19 18:57:43 2008 +0200
@@ -161,6 +161,20 @@ static void get_nonexisting_user_locatio
/* use a reachable but non-existing path as the mail root directory */
str_append(location, storage->base_dir);
str_append(location, PKG_RUNDIR"/user-not-found");
+}
+
+static void drop_unusable_shared_namespaces(struct mail_user *user)
+{
+#define NS_UNUSABLE_FLAGS (NAMESPACE_FLAG_AUTOCREATED | )
+ struct mail_namespace *ns, *next;
+
+ for (ns = user->namespaces; ns != NULL; ns = next) {
+ next = ns->next;
+
+ if ((ns->flags & NAMESPACE_FLAG_USABLE) == 0 &&
+ (ns->flags & NAMESPACE_FLAG_AUTOCREATED) != 0)
+ mail_namespace_destroy(ns);
+ }
}
int shared_storage_get_namespace(struct mail_storage *_storage,
@@ -284,8 +298,7 @@ int shared_storage_get_namespace(struct
ns->prefix, error);
return -1;
}
- /* FIXME: we could remove namespaces here that don't have usable
- mailboxes. otherwise the memory usage could just keep growing. */
+ drop_unusable_shared_namespaces(user);
mail_user_add_namespace(user, ns);
*_name = mail_namespace_fix_sep(ns, name);
@@ -325,6 +338,8 @@ shared_mailbox_open(struct mail_storage
mailbox_open(ns->storage, name, NULL, flags);
if (box == NULL)
shared_mailbox_copy_error(storage, ns);
+ else
+ ns->flags |= NAMESPACE_FLAG_USABLE;
return box;
}
diff -r c56835b33b14 -r 4cf249042df6 src/lib-storage/mail-namespace.h
--- a/src/lib-storage/mail-namespace.h Wed Nov 19 18:46:25 2008 +0200
+++ b/src/lib-storage/mail-namespace.h Wed Nov 19 18:57:43 2008 +0200
@@ -22,7 +22,10 @@ enum namespace_flags {
/* Namespace is created for internal use only. */
NAMESPACE_FLAG_INTERNAL = 0x1000,
/* Namespace was created automatically (for shared mailboxes) */
- NAMESPACE_FLAG_AUTOCREATED = 0x2000
+ NAMESPACE_FLAG_AUTOCREATED = 0x2000,
+ /* Namespace has at least some usable mailboxes. Autocreated namespaces
+ that don't have usable mailboxes may be removed automatically. */
+ NAMESPACE_FLAG_USABLE = 0x4000
};
struct mail_namespace {
diff -r c56835b33b14 -r 4cf249042df6 src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c Wed Nov 19 18:46:25 2008 +0200
+++ b/src/lib-storage/mailbox-list.c Wed Nov 19 18:57:43 2008 +0200
@@ -492,7 +492,12 @@ const struct mailbox_info *
const struct mailbox_info *
mailbox_list_iter_next(struct mailbox_list_iterate_context *ctx)
{
- return ctx->list->v.iter_next(ctx);
+ const struct mailbox_info *info;
+
+ info = ctx->list->v.iter_next(ctx);
+ if (info != NULL)
+ ctx->list->ns->flags |= NAMESPACE_FLAG_USABLE;
+ return info;
}
int mailbox_list_iter_deinit(struct mailbox_list_iterate_context **_ctx)
More information about the dovecot-cvs
mailing list