]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: Added back support for syncing only one mailbox (-m parameter)
authorTimo Sirainen <tss@iki.fi>
Sat, 15 Dec 2012 11:01:09 +0000 (13:01 +0200)
committerTimo Sirainen <tss@iki.fi>
Sat, 15 Dec 2012 11:01:09 +0000 (13:01 +0200)
src/doveadm/dsync/doveadm-dsync.c
src/doveadm/dsync/dsync-brain-mailbox-tree.c
src/doveadm/dsync/dsync-brain-private.h
src/doveadm/dsync/dsync-brain.c
src/doveadm/dsync/dsync-brain.h
src/doveadm/dsync/dsync-ibc-pipe.c
src/doveadm/dsync/dsync-ibc-stream.c
src/doveadm/dsync/dsync-ibc.h
src/doveadm/dsync/dsync-mailbox-tree-fill.c
src/doveadm/dsync/dsync-mailbox-tree.h

index 2e580bc23195ee027ee70da46055d59348e02a0d..9b8b6adc183dd5d09707ee01d5c01640e6b49070 100644 (file)
@@ -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);
index 4155982f0b4503443dd847314744174a6a2c51f6..71c9440f686f8ccc1f4f0dd9dbdbe53da74dc86e 100644 (file)
@@ -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;
index 27602ba595bc5cac244b79d9eb797e13d3c8cad5..81bddaf923d55caa65132c05128aa1301e46cb03 100644 (file)
@@ -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;
index bbcfaab6d856a116cc9c1592adea4df283eb027c..08bac4ce2b6133e55be139c3c182f5a12c64c4a9 100644 (file)
@@ -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);
index 8c0f1f6ac5f5677388d5e42d69be32b1d7fa73d2..db8c3c4534c1264ca1a54a83b540dec1d5e6e87b 100644 (file)
@@ -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);
index ddfa7889dee300b17e1d02dfc5c4624c4682ed56..88781228b4ecfaae071dd17e1495a5bafb1e3e98 100644 (file)
@@ -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
index 0e4822cdec170cbfffee40b45b6e013d8df1f99b..ccb7cd65076e6826dfa9b5fa2d907c079a357ef6 100644 (file)
@@ -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':
index 2ab6641489c1c5a19fa81937e67684f652af2734..e981db40cfcd6e93630c6257ae3575a969292858 100644 (file)
@@ -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;
index 49d346dc200f5fc2ee15b21f24612d610a12f026..e240634576d880d3a951d63ee07ba9c8087af8f4 100644 (file)
@@ -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;
index 7348830c3cf5a32da7ea45351b46b1a91448747d..3c42eed1c52e6495ff0b0559dab5f4b4e73d58b8 100644 (file)
@@ -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 *