]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: Fixed syncing subscription state with doveadm backup.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 15 Jan 2016 13:12:30 +0000 (15:12 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 15 Jan 2016 13:12:30 +0000 (15:12 +0200)
If DSYNC_MAILBOX_TREES_SYNC_TYPE_PRESERVE_REMOTE was set, we could still have
preserved the local subscription state. Also cleaned up the code a bit to
make it clearer.

src/doveadm/dsync/dsync-mailbox-tree-sync.c

index 4076d89322a32ab05f90de3542d4c6705d7c4a40..64fa3f7adb0b4e59706aa59e0f5a015170cefae3 100644 (file)
@@ -1254,11 +1254,22 @@ sync_subscription(struct dsync_mailbox_tree_sync_ctx *ctx,
                  struct dsync_mailbox_node *local_node,
                  struct dsync_mailbox_node *remote_node)
 {
-       if (ctx->sync_type == DSYNC_MAILBOX_TREES_SYNC_TYPE_PRESERVE_LOCAL ||
-           local_node->last_subscription_change >
-               remote_node->last_subscription_change ||
-           (local_node->last_subscription_change ==
-            remote_node->last_subscription_change && local_node->subscribed)) {
+       bool use_local;
+
+       if (ctx->sync_type == DSYNC_MAILBOX_TREES_SYNC_TYPE_PRESERVE_LOCAL)
+               use_local = TRUE;
+       else if (ctx->sync_type == DSYNC_MAILBOX_TREES_SYNC_TYPE_PRESERVE_REMOTE)
+               use_local = FALSE;
+       else if (local_node->last_subscription_change > remote_node->last_subscription_change)
+               use_local = TRUE;
+       else if (local_node->last_subscription_change < remote_node->last_subscription_change)
+               use_local = FALSE;
+       else {
+               /* local and remote have equal timestamps. prefer to subscribe
+                  rather than unsubscribe. */
+               use_local = local_node->subscribed;
+       }
+       if (use_local) {
                /* use local subscription state */
                remote_node->subscribed = local_node->subscribed;
        } else {