dovecot-2.2: Avoid using mail_namespace.storage directly.

dovecot at dovecot.org dovecot at dovecot.org
Thu Jun 6 11:41:56 EEST 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/5ba3d95aba9d
changeset: 16469:5ba3d95aba9d
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jun 06 11:40:27 2013 +0300
description:
Avoid using mail_namespace.storage directly.

diffstat:

 src/doveadm/doveadm-mail-altmove.c            |  34 ++++++++++++---------
 src/doveadm/doveadm-mail.c                    |   8 +++-
 src/lib-storage/index/shared/shared-list.c    |   6 +-
 src/lib-storage/index/shared/shared-storage.c |   3 +-
 src/lib-storage/mail-storage.c                |   4 +-
 src/lib-storage/mailbox-list.c                |   4 +-
 src/plugins/acl/acl-backend-vfile.c           |  42 ++++++++++++++++----------
 src/plugins/acl/acl-shared-storage.c          |   2 +-
 8 files changed, 60 insertions(+), 43 deletions(-)

diffs (273 lines):

diff -r 3467c60014ec -r 5ba3d95aba9d src/doveadm/doveadm-mail-altmove.c
--- a/src/doveadm/doveadm-mail-altmove.c	Thu Jun 06 11:16:05 2013 +0300
+++ b/src/doveadm/doveadm-mail-altmove.c	Thu Jun 06 11:40:27 2013 +0300
@@ -40,12 +40,13 @@
 }
 
 static int
-ns_purge(struct doveadm_mail_cmd_context *ctx, struct mail_namespace *ns)
+ns_purge(struct doveadm_mail_cmd_context *ctx, struct mail_namespace *ns,
+	 struct mail_storage *storage)
 {
-	if (mail_storage_purge(ns->storage) < 0) {
+	if (mail_storage_purge(storage) < 0) {
 		i_error("Purging namespace '%s' failed: %s", ns->prefix,
-			mail_storage_get_last_error(ns->storage, NULL));
-		doveadm_mail_failed_storage(ctx, ns->storage);
+			mail_storage_get_last_error(storage, NULL));
+		doveadm_mail_failed_storage(ctx, storage);
 		return -1;
 	}
 	return 0;
@@ -62,7 +63,7 @@
 	const struct mailbox_info *info;
 	struct mail_namespace *ns, *prev_ns = NULL;
 	ARRAY(struct mail_storage *) purged_storages;
-	struct mail_storage *const *storages;
+	struct mail_storage *const *storages, *ns_storage, *prev_storage = NULL;
 	unsigned int i, count;
 	int ret = 0;
 
@@ -70,13 +71,15 @@
 	iter = doveadm_mailbox_list_iter_init(_ctx, user, _ctx->search_args,
 					      iter_flags);
 	while ((info = doveadm_mailbox_list_iter_next(iter)) != NULL) T_BEGIN {
-		if (info->ns != prev_ns) {
-			if (prev_ns != NULL) {
-				if (ns_purge(_ctx, prev_ns) < 0)
+		ns_storage = mail_namespace_get_default_storage(info->ns);
+		if (ns_storage != prev_storage) {
+			if (prev_storage != NULL) {
+				if (ns_purge(_ctx, prev_ns, prev_storage) < 0)
 					ret = -1;
 				array_append(&purged_storages,
-					     &prev_ns->storage, 1);
+					     &prev_storage, 1);
 			}
+			prev_storage = ns_storage;
 			prev_ns = info->ns;
 		}
 		if (cmd_altmove_box(_ctx, info, _ctx->search_args, ctx->reverse) < 0)
@@ -85,10 +88,10 @@
 	if (doveadm_mailbox_list_iter_deinit(&iter) < 0)
 		ret = -1;
 
-	if (prev_ns != NULL) {
-		if (ns_purge(_ctx, prev_ns) < 0)
+	if (prev_storage != NULL) {
+		if (ns_purge(_ctx, prev_ns, prev_storage) < 0)
 			ret = -1;
-		array_append(&purged_storages, &prev_ns->storage, 1);
+		array_append(&purged_storages, &prev_storage, 1);
 	}
 
 	/* make sure all private storages have been purged */
@@ -97,14 +100,15 @@
 		if (ns->type != MAIL_NAMESPACE_TYPE_PRIVATE)
 			continue;
 
+		ns_storage = mail_namespace_get_default_storage(ns);
 		for (i = 0; i < count; i++) {
-			if (ns->storage == storages[i])
+			if (ns_storage == storages[i])
 				break;
 		}
 		if (i == count) {
-			if (ns_purge(_ctx, ns) < 0)
+			if (ns_purge(_ctx, ns, ns_storage) < 0)
 				ret = -1;
-			array_append(&purged_storages, &ns->storage, 1);
+			array_append(&purged_storages, &ns_storage, 1);
 			storages = array_get(&purged_storages, &count);
 		}
 	}
diff -r 3467c60014ec -r 5ba3d95aba9d src/doveadm/doveadm-mail.c
--- a/src/doveadm/doveadm-mail.c	Thu Jun 06 11:16:05 2013 +0300
+++ b/src/doveadm/doveadm-mail.c	Thu Jun 06 11:40:27 2013 +0300
@@ -107,6 +107,7 @@
 cmd_purge_run(struct doveadm_mail_cmd_context *ctx, struct mail_user *user)
 {
 	struct mail_namespace *ns;
+	struct mail_storage *storage;
 	int ret = 0;
 
 	for (ns = user->namespaces; ns != NULL; ns = ns->next) {
@@ -114,10 +115,11 @@
 		    ns->alias_for != NULL)
 			continue;
 
-		if (mail_storage_purge(ns->storage) < 0) {
+		storage = mail_namespace_get_default_storage(ns);
+		if (mail_storage_purge(storage) < 0) {
 			i_error("Purging namespace '%s' failed: %s", ns->prefix,
-				mail_storage_get_last_error(ns->storage, NULL));
-			doveadm_mail_failed_storage(ctx, ns->storage);
+				mail_storage_get_last_error(storage, NULL));
+			doveadm_mail_failed_storage(ctx, storage);
 			ret = -1;
 		}
 	}
diff -r 3467c60014ec -r 5ba3d95aba9d src/lib-storage/index/shared/shared-list.c
--- a/src/lib-storage/index/shared/shared-list.c	Thu Jun 06 11:16:05 2013 +0300
+++ b/src/lib-storage/index/shared/shared-list.c	Thu Jun 06 11:40:27 2013 +0300
@@ -51,8 +51,7 @@
 			return -1;
 	}
 	*list = ns->list;
-	*storage_r = ns->storage;
-	return 0;
+	return mailbox_list_get_storage(list, vname, storage_r);
 }
 
 static char shared_list_get_hierarchy_sep(struct mailbox_list *list ATTR_UNUSED)
@@ -66,7 +65,8 @@
 {
 	struct mail_namespace *ns = list->ns;
 
-	if (list->ns->storage == NULL || name == NULL ||
+	if (mail_namespace_get_default_storage(list->ns) == NULL ||
+	    name == NULL ||
 	    shared_storage_get_namespace(&ns, &name) < 0) {
 		/* we don't have a directory we can use. */
 		*path_r = NULL;
diff -r 3467c60014ec -r 5ba3d95aba9d src/lib-storage/index/shared/shared-storage.c
--- a/src/lib-storage/index/shared/shared-storage.c	Thu Jun 06 11:16:05 2013 +0300
+++ b/src/lib-storage/index/shared/shared-storage.c	Thu Jun 06 11:40:27 2013 +0300
@@ -346,7 +346,8 @@
 	*_ns = new_ns;
 	if (_storage->class_flags == 0) {
 		/* flags are unset if we were using "auto" storage */
-		_storage->class_flags = new_ns->storage->class_flags;
+		_storage->class_flags =
+			mail_namespace_get_default_storage(new_ns)->class_flags;
 	}
 
 	mail_user_add_namespace(user, &new_ns);
diff -r 3467c60014ec -r 5ba3d95aba9d src/lib-storage/mail-storage.c
--- a/src/lib-storage/mail-storage.c	Thu Jun 06 11:16:05 2013 +0300
+++ b/src/lib-storage/mail-storage.c	Thu Jun 06 11:40:27 2013 +0300
@@ -655,8 +655,8 @@
 	}
 
 	if (mailbox_list_get_storage(&new_list, vname, &storage) < 0) {
-		/* just use the first storage. FIXME: does this break? */
-		storage = list->ns->storage;
+		/* just use the default storage. FIXME: does this break? */
+		storage = mail_namespace_get_default_storage(list->ns);
 	}
 
 	T_BEGIN {
diff -r 3467c60014ec -r 5ba3d95aba9d src/lib-storage/mailbox-list.c
--- a/src/lib-storage/mailbox-list.c	Thu Jun 06 11:16:05 2013 +0300
+++ b/src/lib-storage/mailbox-list.c	Thu Jun 06 11:40:27 2013 +0300
@@ -776,7 +776,7 @@
 	if ((*list)->v.get_storage != NULL)
 		return (*list)->v.get_storage(list, vname, storage_r);
 	else {
-		*storage_r = (*list)->ns->storage;
+		*storage_r = mail_namespace_get_default_storage((*list)->ns);
 		return 0;
 	}
 }
@@ -784,7 +784,7 @@
 void mailbox_list_get_default_storage(struct mailbox_list *list,
 				      struct mail_storage **storage)
 {
-	*storage = list->ns->storage;
+	*storage = mail_namespace_get_default_storage(list->ns);
 }
 
 char mailbox_list_get_hierarchy_sep(struct mailbox_list *list)
diff -r 3467c60014ec -r 5ba3d95aba9d src/plugins/acl/acl-backend-vfile.c
--- a/src/plugins/acl/acl-backend-vfile.c	Thu Jun 06 11:16:05 2013 +0300
+++ b/src/plugins/acl/acl-backend-vfile.c	Thu Jun 06 11:40:27 2013 +0300
@@ -127,35 +127,43 @@
 }
 
 static const char *
-acl_backend_vfile_get_local_dir(struct acl_backend *backend, const char *name)
+acl_backend_vfile_get_local_dir(struct acl_backend *backend,
+				const char *name)
 {
 	struct mail_namespace *ns = mailbox_list_get_namespace(backend->list);
+	struct mailbox_list *list = ns->list;
+	struct mail_storage *storage;
 	enum mailbox_list_path_type type;
-	const char *dir, *inbox, *error;
+	const char *dir, *inbox, *vname, *error;
 
 	if (*name == '\0')
 		name = NULL;
-	else if (!mailbox_list_is_valid_name(ns->list, name, &error))
+	else if (!mailbox_list_is_valid_name(list, name, &error))
 		return NULL;
 
 	/* ACL files are very important. try to keep them among the main
 	   mail files. that's not possible though with a) if the mailbox is
 	   a file or b) if the mailbox path doesn't point to filesystem. */
-	type = mail_storage_is_mailbox_file(ns->storage) ||
-		(ns->storage->class_flags & MAIL_STORAGE_CLASS_FLAG_NO_ROOT) != 0 ?
+	vname = mailbox_list_get_vname(backend->list, name);
+	if (mailbox_list_get_storage(&list, vname, &storage) < 0)
+		return NULL;
+	i_assert(list == ns->list);
+
+	type = mail_storage_is_mailbox_file(storage) ||
+		(storage->class_flags & MAIL_STORAGE_CLASS_FLAG_NO_ROOT) != 0 ?
 		MAILBOX_LIST_PATH_TYPE_CONTROL : MAILBOX_LIST_PATH_TYPE_MAILBOX;
 	if (name == NULL) {
-		if (!mailbox_list_get_root_path(ns->list, type, &dir))
+		if (!mailbox_list_get_root_path(list, type, &dir))
 			return FALSE;
 	} else {
-		if (mailbox_list_get_path(ns->list, name, type, &dir) <= 0)
+		if (mailbox_list_get_path(list, name, type, &dir) <= 0)
 			return NULL;
 	}
 
 	/* verify that the directory isn't same as INBOX's directory.
 	   this is mainly for Maildir. */
 	if (name == NULL &&
-	    mailbox_list_get_path(ns->list, "INBOX",
+	    mailbox_list_get_path(list, "INBOX",
 				  MAILBOX_LIST_PATH_TYPE_MAILBOX, &inbox) > 0 &&
 	    strcmp(inbox, dir) == 0) {
 		/* can't have default ACLs with this setup */
@@ -177,15 +185,17 @@
 	aclobj->aclobj.backend = _backend;
 	aclobj->aclobj.name = i_strdup(name);
 
-	if (backend->global_dir != NULL) T_BEGIN {
-		vname = mailbox_list_get_vname(backend->backend.list, name);
-		aclobj->global_path = i_strconcat(backend->global_dir, "/",
-						  vname, NULL);
+	T_BEGIN {
+		if (backend->global_dir != NULL) {
+			vname = mailbox_list_get_vname(backend->backend.list, name);
+			aclobj->global_path =
+				i_strconcat(backend->global_dir, "/", vname, NULL);
+		}
+
+		dir = acl_backend_vfile_get_local_dir(_backend, name);
+		aclobj->local_path = dir == NULL ? NULL :
+			i_strconcat(dir, "/"ACL_FILENAME, NULL);
 	} T_END;
-
-	dir = acl_backend_vfile_get_local_dir(_backend, name);
-	aclobj->local_path = dir == NULL ? NULL :
-		i_strconcat(dir, "/"ACL_FILENAME, NULL);
 	return &aclobj->aclobj;
 }
 
diff -r 3467c60014ec -r 5ba3d95aba9d src/plugins/acl/acl-shared-storage.c
--- a/src/plugins/acl/acl-shared-storage.c	Thu Jun 06 11:16:05 2013 +0300
+++ b/src/plugins/acl/acl-shared-storage.c	Thu Jun 06 11:40:27 2013 +0300
@@ -84,7 +84,7 @@
 {
 	struct acl_user *auser = ACL_USER_CONTEXT(ns->user);
 	struct acl_mailbox_list *alist = ACL_LIST_CONTEXT(ns->list);
-	struct mail_storage *storage = ns->storage;
+	struct mail_storage *storage = mail_namespace_get_default_storage(ns);
 	struct acl_lookup_dict_iter *iter;
 	const char *name;
 


More information about the dovecot-cvs mailing list