changeset 19563:11872411f6a0

dsync: Fixed syncing subscription state with doveadm backup. 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.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Fri, 15 Jan 2016 15:12:30 +0200
parents 388bd0863909
children 4d671a0e6219
files src/doveadm/dsync/dsync-mailbox-tree-sync.c
diffstat 1 files changed, 16 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/doveadm/dsync/dsync-mailbox-tree-sync.c	Fri Jan 15 15:04:21 2016 +0200
+++ b/src/doveadm/dsync/dsync-mailbox-tree-sync.c	Fri Jan 15 15:12:30 2016 +0200
@@ -1254,11 +1254,22 @@
 		  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 {