From: Timo Sirainen Date: Sat, 15 Dec 2012 11:01:09 +0000 (+0200) Subject: dsync: Added back support for syncing only one mailbox (-m parameter) X-Git-Tag: 2.2.beta1~32 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=707f172cd4e4c91af86ff5bd82a60a873dec6f70;p=thirdparty%2Fdovecot%2Fcore.git dsync: Added back support for syncing only one mailbox (-m parameter) --- diff --git a/src/doveadm/dsync/doveadm-dsync.c b/src/doveadm/dsync/doveadm-dsync.c index 2e580bc231..9b8b6adc18 100644 --- a/src/doveadm/dsync/doveadm-dsync.c +++ b/src/doveadm/dsync/doveadm-dsync.c @@ -373,7 +373,7 @@ cmd_dsync_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) if (doveadm_debug) brain_flags |= DSYNC_BRAIN_FLAG_DEBUG; - brain = dsync_brain_master_init(user, ibc, sync_ns, + brain = dsync_brain_master_init(user, ibc, sync_ns, ctx->mailbox, ctx->sync_type, brain_flags, ctx->state_input == NULL ? "" : ctx->state_input); diff --git a/src/doveadm/dsync/dsync-brain-mailbox-tree.c b/src/doveadm/dsync/dsync-brain-mailbox-tree.c index 4155982f0b..71c9440f68 100644 --- a/src/doveadm/dsync/dsync-brain-mailbox-tree.c +++ b/src/doveadm/dsync/dsync-brain-mailbox-tree.c @@ -76,14 +76,14 @@ void dsync_brain_mailbox_trees_init(struct dsync_brain *brain) /* fill the local mailbox tree */ if (brain->sync_ns != NULL) { if (dsync_mailbox_tree_fill(brain->local_mailbox_tree, - brain->sync_ns) < 0) + brain->sync_ns, brain->sync_box) < 0) brain->failed = TRUE; } else { for (ns = brain->user->namespaces; ns != NULL; ns = ns->next) { if (!dsync_brain_want_namespace(brain, ns)) continue; if (dsync_mailbox_tree_fill(brain->local_mailbox_tree, - ns) < 0) + ns, brain->sync_box) < 0) brain->failed = TRUE; } } @@ -92,7 +92,6 @@ void dsync_brain_mailbox_trees_init(struct dsync_brain *brain) dsync_mailbox_tree_iter_init(brain->local_mailbox_tree); } - void dsync_brain_send_mailbox_tree(struct dsync_brain *brain) { struct dsync_mailbox_node *node; diff --git a/src/doveadm/dsync/dsync-brain-private.h b/src/doveadm/dsync/dsync-brain-private.h index 27602ba595..81bddaf923 100644 --- a/src/doveadm/dsync/dsync-brain-private.h +++ b/src/doveadm/dsync/dsync-brain-private.h @@ -46,6 +46,7 @@ struct dsync_brain { struct mail_user *user; struct dsync_ibc *ibc; struct mail_namespace *sync_ns; + char *sync_box; enum dsync_brain_sync_type sync_type; char hierarchy_sep; diff --git a/src/doveadm/dsync/dsync-brain.c b/src/doveadm/dsync/dsync-brain.c index bbcfaab6d8..08bac4ce2b 100644 --- a/src/doveadm/dsync/dsync-brain.c +++ b/src/doveadm/dsync/dsync-brain.c @@ -83,7 +83,7 @@ dsync_brain_set_flags(struct dsync_brain *brain, enum dsync_brain_flags flags) struct dsync_brain * dsync_brain_master_init(struct mail_user *user, struct dsync_ibc *ibc, - struct mail_namespace *sync_ns, + struct mail_namespace *sync_ns, const char *sync_box, enum dsync_brain_sync_type sync_type, enum dsync_brain_flags flags, const char *state) @@ -99,6 +99,7 @@ dsync_brain_master_init(struct mail_user *user, struct dsync_ibc *ibc, brain->sync_type = sync_type; if (sync_ns != NULL) brain->sync_ns = sync_ns; + brain->sync_box = p_strdup(brain->pool, sync_box); brain->master_brain = TRUE; dsync_brain_set_flags(brain, flags); @@ -120,6 +121,7 @@ dsync_brain_master_init(struct mail_user *user, struct dsync_ibc *ibc, memset(&ibc_set, 0, sizeof(ibc_set)); ibc_set.sync_ns_prefix = sync_ns == NULL ? NULL : sync_ns->prefix; + ibc_set.sync_box = sync_box; ibc_set.sync_type = sync_type; /* reverse the backup direction for the slave */ ibc_set.brain_flags = flags & ~(DSYNC_BRAIN_FLAG_BACKUP_SEND | @@ -183,6 +185,7 @@ static bool dsync_brain_slave_recv_handshake(struct dsync_brain *brain) brain->sync_ns = mail_namespace_find(brain->user->namespaces, ibc_set->sync_ns_prefix); } + brain->sync_box = p_strdup(brain->pool, ibc_set->sync_box); i_assert(brain->sync_type == DSYNC_BRAIN_SYNC_TYPE_UNKNOWN); brain->sync_type = ibc_set->sync_type; dsync_brain_set_flags(brain, ibc_set->brain_flags); diff --git a/src/doveadm/dsync/dsync-brain.h b/src/doveadm/dsync/dsync-brain.h index 8c0f1f6ac5..db8c3c4534 100644 --- a/src/doveadm/dsync/dsync-brain.h +++ b/src/doveadm/dsync/dsync-brain.h @@ -28,7 +28,7 @@ enum dsync_brain_sync_type { struct dsync_brain * dsync_brain_master_init(struct mail_user *user, struct dsync_ibc *ibc, - struct mail_namespace *sync_ns, + struct mail_namespace *sync_ns, const char *sync_box, enum dsync_brain_sync_type sync_type, enum dsync_brain_flags flags, const char *state); diff --git a/src/doveadm/dsync/dsync-ibc-pipe.c b/src/doveadm/dsync/dsync-ibc-pipe.c index ddfa7889de..88781228b4 100644 --- a/src/doveadm/dsync/dsync-ibc-pipe.c +++ b/src/doveadm/dsync/dsync-ibc-pipe.c @@ -157,6 +157,7 @@ dsync_ibc_pipe_send_handshake(struct dsync_ibc *ibc, item = dsync_ibc_pipe_push_item(pipe->remote, ITEM_HANDSHAKE); item->u.set = *set; item->u.set.sync_ns_prefix = p_strdup(item->pool, set->sync_ns_prefix); + item->u.set.sync_box = p_strdup(item->pool, set->sync_box); } static enum dsync_ibc_recv_ret diff --git a/src/doveadm/dsync/dsync-ibc-stream.c b/src/doveadm/dsync/dsync-ibc-stream.c index 0e4822cdec..ccb7cd6507 100644 --- a/src/doveadm/dsync/dsync-ibc-stream.c +++ b/src/doveadm/dsync/dsync-ibc-stream.c @@ -60,7 +60,7 @@ static const struct { { NULL, '\0', NULL, NULL }, { .name = "handshake", .chr = 'H', - .optional_keys = "sync_ns_prefix sync_type debug sync_all_namespaces " + .optional_keys = "sync_ns_prefix sync_box sync_type debug sync_all_namespaces " "mails_have_guids send_guid_requests backup_send backup_recv" }, { .name = "mailbox_state", @@ -514,6 +514,8 @@ dsync_ibc_stream_send_handshake(struct dsync_ibc *_ibc, dsync_serializer_encode_add(encoder, "sync_ns_prefix", set->sync_ns_prefix); } + if (set->sync_box != NULL) + dsync_serializer_encode_add(encoder, "sync_box", set->sync_box); sync_type[0] = sync_type[1] = '\0'; switch (set->sync_type) { @@ -574,6 +576,8 @@ dsync_ibc_stream_recv_handshake(struct dsync_ibc *_ibc, if (dsync_deserializer_decode_try(decoder, "sync_ns_prefix", &value)) set->sync_ns_prefix = p_strdup(pool, value); + if (dsync_deserializer_decode_try(decoder, "sync_box", &value)) + set->sync_box = p_strdup(pool, value); if (dsync_deserializer_decode_try(decoder, "sync_type", &value)) { switch (value[0]) { case 'f': diff --git a/src/doveadm/dsync/dsync-ibc.h b/src/doveadm/dsync/dsync-ibc.h index 2ab6641489..e981db40cf 100644 --- a/src/doveadm/dsync/dsync-ibc.h +++ b/src/doveadm/dsync/dsync-ibc.h @@ -31,6 +31,8 @@ enum dsync_ibc_recv_ret { struct dsync_ibc_settings { /* if non-NULL, sync only this namespace */ const char *sync_ns_prefix; + /* if non-NULL, sync only this mailbox name */ + const char *sync_box; enum dsync_brain_sync_type sync_type; enum dsync_brain_flags brain_flags; diff --git a/src/doveadm/dsync/dsync-mailbox-tree-fill.c b/src/doveadm/dsync/dsync-mailbox-tree-fill.c index 49d346dc20..e240634576 100644 --- a/src/doveadm/dsync/dsync-mailbox-tree-fill.c +++ b/src/doveadm/dsync/dsync-mailbox-tree-fill.c @@ -170,7 +170,7 @@ dsync_mailbox_tree_add_change_timestamps(struct dsync_mailbox_tree *tree, } int dsync_mailbox_tree_fill(struct dsync_mailbox_tree *tree, - struct mail_namespace *ns) + struct mail_namespace *ns, const char *box_name) { const enum mailbox_list_iter_flags list_flags = MAILBOX_LIST_ITER_NO_AUTO_BOXES; @@ -181,6 +181,7 @@ int dsync_mailbox_tree_fill(struct dsync_mailbox_tree *tree, struct mailbox_list_iterate_context *iter; struct dsync_mailbox_node *node; const struct mailbox_info *info; + const char *list_pattern = box_name != NULL ? box_name : "*"; int ret = 0; i_assert(mail_namespace_get_sep(ns) == tree->sep); @@ -195,7 +196,7 @@ int dsync_mailbox_tree_fill(struct dsync_mailbox_tree *tree, } /* first add all of the existing mailboxes */ - iter = mailbox_list_iter_init(ns->list, "*", list_flags); + iter = mailbox_list_iter_init(ns->list, list_pattern, list_flags); while ((info = mailbox_list_iter_next(iter)) != NULL) { if (dsync_mailbox_tree_add(tree, info) < 0) ret = -1; @@ -206,7 +207,7 @@ int dsync_mailbox_tree_fill(struct dsync_mailbox_tree *tree, } /* add subscriptions */ - iter = mailbox_list_iter_init(ns->list, "*", subs_list_flags); + iter = mailbox_list_iter_init(ns->list, list_pattern, subs_list_flags); while ((info = mailbox_list_iter_next(iter)) != NULL) { if (dsync_mailbox_tree_add_node(tree, info, &node) < 0) ret = -1; diff --git a/src/doveadm/dsync/dsync-mailbox-tree.h b/src/doveadm/dsync/dsync-mailbox-tree.h index 7348830c3c..3c42eed1c5 100644 --- a/src/doveadm/dsync/dsync-mailbox-tree.h +++ b/src/doveadm/dsync/dsync-mailbox-tree.h @@ -121,9 +121,10 @@ const char *dsync_mailbox_node_get_full_name(const struct dsync_mailbox_tree *tr void dsync_mailbox_node_copy_data(struct dsync_mailbox_node *dest, const struct dsync_mailbox_node *src); -/* Add nodes to tree from the given namespace. */ +/* Add nodes to tree from the given namespace. If box_name is non-NULL, + add only that mailbox to the tree. */ int dsync_mailbox_tree_fill(struct dsync_mailbox_tree *tree, - struct mail_namespace *ns); + struct mail_namespace *ns, const char *box_name); /* Return all known deleted mailboxes and directories. */ const struct dsync_mailbox_delete *