dovecot-2.1: dsync: Don't remove other namespaces entirely, just...

dovecot at dovecot.org dovecot at dovecot.org
Wed Jan 4 16:46:22 EET 2012


details:   http://hg.dovecot.org/dovecot-2.1/rev/4f995c6e971b
changeset: 13888:4f995c6e971b
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Jan 04 16:46:12 2012 +0200
description:
dsync: Don't remove other namespaces entirely, just skip the unwanted ones.
This fixes incorrectly removing subscriptions=no namespaces entries from
subscriptions.

diffstat:

 src/doveadm/dsync/dsync-worker-local.c |  96 +++++++++++++--------------------
 1 files changed, 37 insertions(+), 59 deletions(-)

diffs (181 lines):

diff -r 11a5bb865eba -r 4f995c6e971b src/doveadm/dsync/dsync-worker-local.c
--- a/src/doveadm/dsync/dsync-worker-local.c	Wed Jan 04 15:22:26 2012 +0200
+++ b/src/doveadm/dsync/dsync-worker-local.c	Wed Jan 04 16:46:12 2012 +0200
@@ -94,7 +94,7 @@
 	struct hash_table *dir_changes_hash;
 
 	char alt_char;
-	ARRAY_DEFINE(subs_namespaces, struct mail_namespace *);
+	ARRAY_DEFINE(wanted_namespaces, struct mail_namespace *);
 
 	mailbox_guid_t selected_box_guid;
 	struct mailbox *selected_box;
@@ -151,56 +151,23 @@
 	return h;
 }
 
-static struct mail_namespace *
-namespace_find_set(struct mail_user *user,
-		   const struct mail_namespace_settings *set)
+static bool local_worker_want_namespace(struct mail_namespace *ns)
+{
+	return strcmp(ns->unexpanded_set->location,
+		      SETTING_STRVAR_UNEXPANDED) == 0;
+}
+
+static void dsync_check_namespaces(struct local_dsync_worker *worker)
 {
 	struct mail_namespace *ns;
 
-	for (ns = user->namespaces; ns != NULL; ns = ns->next) {
-		/* compare settings pointers so that it'll work
-		   for shared namespaces */
-		if (ns->set == set)
-			return ns;
+	for (ns = worker->user->namespaces; ns != NULL; ns = ns->next) {
+		if (local_worker_want_namespace(ns))
+			return;
 	}
-	return NULL;
-}
-
-static void dsync_drop_extra_namespaces(struct local_dsync_worker *worker)
-{
-	struct mail_user *user = worker->user;
-	struct mail_namespace_settings *const *ns_unset, *const *ns_set;
-	struct mail_namespace *ns;
-	unsigned int i, count, count2;
-
-	if (!array_is_created(&user->unexpanded_set->namespaces))
-		return;
-
-	/* drop all namespaces that have a location defined internally */
-	ns_unset = array_get(&user->unexpanded_set->namespaces, &count);
-	ns_set = array_get(&user->set->namespaces, &count2);
-	i_assert(count == count2);
-	for (i = 0; i < count; i++) {
-		if (strcmp(ns_unset[i]->location,
-			   SETTING_STRVAR_UNEXPANDED) == 0)
-			continue;
-
-		ns = namespace_find_set(user, ns_set[i]);
-		i_assert(ns != NULL);
-		if ((ns->flags & NAMESPACE_FLAG_SUBSCRIPTIONS) == 0) {
-			/* remember the subscriptions=no namespaces so we can
-			   handle their subscriptions in parent namespaces
-			   properly */
-			mail_namespace_ref(ns);
-			array_append(&worker->subs_namespaces, &ns, 1);
-		}
-		mail_namespace_destroy(ns);
-	}
-	if (user->namespaces == NULL) {
-		i_fatal("All your namespaces have a location setting. "
-			"It should be empty (default mail_location) in the "
-			"namespace to be converted.");
-	}
+	i_fatal("All your namespaces have a location setting. "
+		"It should be empty (default mail_location) in the "
+		"namespace to be converted.");
 }
 
 struct dsync_worker *
@@ -220,8 +187,8 @@
 				  mailbox_guid_hash, mailbox_guid_cmp);
 	i_array_init(&worker->saved_uids, 128);
 	i_array_init(&worker->msg_get_queue, 32);
-	p_array_init(&worker->subs_namespaces, pool, 8);
-	dsync_drop_extra_namespaces(worker);
+	p_array_init(&worker->wanted_namespaces, pool, 8);
+	dsync_check_namespaces(worker);
 
 	mail_user_ref(worker->user);
 	return &worker->worker;
@@ -231,13 +198,9 @@
 {
 	struct local_dsync_worker *worker =
 		(struct local_dsync_worker *)_worker;
-	struct mail_namespace **nsp;
 
 	i_assert(worker->save_input == NULL);
 
-	array_foreach_modifiable(&worker->subs_namespaces, nsp)
-		mail_namespace_unref(nsp);
-
 	local_worker_msg_box_close(worker);
 	local_worker_mailbox_close(worker);
 	mail_user_unref(&worker->user);
@@ -417,7 +380,7 @@
 		hash_table_create(default_pool, worker->pool, 0,
 				  dir_change_hash, dir_change_cmp);
 	for (ns = worker->user->namespaces; ns != NULL; ns = ns->next) {
-		if (ns->alias_for != NULL)
+		if (ns->alias_for != NULL || !local_worker_want_namespace(ns))
 			continue;
 
 		if (dsync_worker_get_list_mailbox_log(worker, ns->list) < 0)
@@ -537,7 +500,10 @@
 
 	memset(dsync_box_r, 0, sizeof(*dsync_box_r));
 
-	info = mailbox_list_iter_next(iter->list_iter);
+	while ((info = mailbox_list_iter_next(iter->list_iter)) != NULL) {
+		if (local_worker_want_namespace(info->ns))
+			break;
+	}
 	if (info == NULL)
 		return iter_next_deleted(iter, worker, dsync_box_r);
 
@@ -646,16 +612,18 @@
 	struct local_dsync_worker *worker =
 		(struct local_dsync_worker *)_worker;
 	struct local_dsync_worker_subs_iter *iter;
-	enum mailbox_list_iter_flags list_flags =
+	const enum mailbox_list_iter_flags list_flags =
 		MAILBOX_LIST_ITER_SKIP_ALIASES |
 		MAILBOX_LIST_ITER_SELECT_SUBSCRIBED;
+	const enum namespace_type namespace_mask =
+		NAMESPACE_PRIVATE | NAMESPACE_SHARED | NAMESPACE_PUBLIC;
 	static const char *patterns[] = { "*", NULL };
 
 	iter = i_new(struct local_dsync_worker_subs_iter, 1);
 	iter->iter.worker = _worker;
 	iter->list_iter =
 		mailbox_list_iter_init_namespaces(worker->user->namespaces,
-						  patterns, NAMESPACE_PRIVATE,
+						  patterns, namespace_mask,
 						  list_flags);
 	(void)dsync_worker_get_mailbox_log(worker);
 	return &iter->iter;
@@ -675,11 +643,18 @@
 
 	memset(rec_r, 0, sizeof(*rec_r));
 
-	info = mailbox_list_iter_next(iter->list_iter);
+	while ((info = mailbox_list_iter_next(iter->list_iter)) != NULL) {
+		if (local_worker_want_namespace(info->ns) ||
+		    (info->ns->flags & NAMESPACE_FLAG_SUBSCRIPTIONS) == 0)
+			break;
+	}
 	if (info == NULL)
 		return -1;
 
 	storage_name = mailbox_list_get_storage_name(info->ns->list, info->name);
+	if ((info->ns->flags & NAMESPACE_FLAG_SUBSCRIPTIONS) == 0)
+		storage_name = t_strconcat(info->ns->prefix, storage_name, NULL);
+
 	dsync_str_sha_to_guid(storage_name, &change_lookup.name_sha1);
 	change_lookup.list = info->ns->list;
 
@@ -691,7 +666,10 @@
 		change->unsubscribed = FALSE;
 		rec_r->last_change = change->last_subs_change;
 	}
-	rec_r->ns_prefix = info->ns->prefix;
+	if ((info->ns->flags & NAMESPACE_FLAG_SUBSCRIPTIONS) == 0)
+		rec_r->ns_prefix = "";
+	else
+		rec_r->ns_prefix = info->ns->prefix;
 	rec_r->vname = info->name;
 	rec_r->storage_name = storage_name;
 	return 1;


More information about the dovecot-cvs mailing list