]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
dsync: Don't give errors when doing a remote sync and there are no changes.
authorTimo Sirainen <tss@iki.fi>
Mon, 12 Jul 2010 15:27:51 +0000 (16:27 +0100)
committerTimo Sirainen <tss@iki.fi>
Mon, 12 Jul 2010 15:27:51 +0000 (16:27 +0100)
src/dsync/dsync-brain.c
src/dsync/dsync-worker.c

index 6e62d057d299feb6ed01c0d3f9e5a74d0b5941c9..b15305bf13d88187b6747fd76ffde1233183ee39 100644 (file)
@@ -710,18 +710,26 @@ dsync_brain_get_changed_mailboxes(struct dsync_brain *brain,
        }
 }
 
-static void dsync_brain_sync_msgs(struct dsync_brain *brain)
+static bool dsync_brain_sync_msgs(struct dsync_brain *brain)
 {
        ARRAY_TYPE(dsync_brain_mailbox) mailboxes;
        pool_t pool;
+       bool ret;
 
        pool = pool_alloconly_create("dsync changed mailboxes", 10240);
        p_array_init(&mailboxes, pool, 128);
        dsync_brain_get_changed_mailboxes(brain, &mailboxes,
                (brain->flags & DSYNC_BRAIN_FLAG_FULL_SYNC) != 0);
-       brain->mailbox_sync = dsync_brain_msg_sync_init(brain, &mailboxes);
-       dsync_brain_msg_sync_more(brain->mailbox_sync);
+       if (array_count(&mailboxes) > 0) {
+               brain->mailbox_sync =
+                       dsync_brain_msg_sync_init(brain, &mailboxes);
+               dsync_brain_msg_sync_more(brain->mailbox_sync);
+               ret = TRUE;
+       } else {
+               ret = FALSE;
+       }
        pool_unref(&pool);
+       return ret;
 }
 
 static void
@@ -748,6 +756,11 @@ dsync_brain_sync_update_mailboxes(struct dsync_brain *brain)
                dsync_worker_has_failed(brain->src_worker) ||
                dsync_worker_has_failed(brain->dest_worker);
 
+       if (brain->mailbox_sync == NULL) {
+               /* no mailboxes changed */
+               return;
+       }
+
        array_foreach(&brain->mailbox_sync->mailboxes, mailbox) {
                /* don't update mailboxes if any changes had failed.
                   for example if some messages couldn't be saved, we don't
@@ -813,6 +826,9 @@ void dsync_brain_sync(struct dsync_brain *brain)
                dsync_worker_subs_input(brain->dest_subs_list);
                break;
        case DSYNC_STATE_SYNC_MAILBOXES:
+               dsync_worker_set_input_callback(brain->src_worker, NULL, NULL);
+               dsync_worker_set_input_callback(brain->dest_worker, NULL, NULL);
+
                dsync_brain_sync_mailboxes(brain);
                dsync_brain_sync_dirs(brain);
                brain->state++;
@@ -822,8 +838,10 @@ void dsync_brain_sync(struct dsync_brain *brain)
                brain->state++;
                /* fall through */
        case DSYNC_STATE_SYNC_MSGS:
-               dsync_brain_sync_msgs(brain);
-               break;
+               if (dsync_brain_sync_msgs(brain))
+                       break;
+               brain->state++;
+               /* no mailboxes changed */
        case DSYNC_STATE_SYNC_MSGS_FLUSH:
                /* wait until all saves are done, so we don't try to close
                   the mailbox too early */
index 77599e17f9425431f87f832fc3765df9d8d51012..ff5ab50538a8cd8a9a92d7f5d6eed3601b05cb71 100644 (file)
@@ -108,6 +108,7 @@ dsync_worker_msg_iter_init(struct dsync_worker *worker,
                           const mailbox_guid_t mailboxes[],
                           unsigned int mailbox_count)
 {
+       i_assert(mailbox_count > 0);
        return worker->v.msg_iter_init(worker, mailboxes, mailbox_count);
 }