From: Timo Sirainen Date: Mon, 5 Jul 2010 11:35:52 +0000 (+0100) Subject: dsync backup: Fail if it looks like backup is running in wrong direction. X-Git-Tag: 2.0.rc2~41 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8e0c3abc4e32188b92542358f9bff31e72f534e0;p=thirdparty%2Fdovecot%2Fcore.git dsync backup: Fail if it looks like backup is running in wrong direction. --HG-- branch : HEAD --- diff --git a/src/dsync/dsync-brain.c b/src/dsync/dsync-brain.c index 3885c69a19..b46098782d 100644 --- a/src/dsync/dsync-brain.c +++ b/src/dsync/dsync-brain.c @@ -9,6 +9,11 @@ #include +#define DSYNC_WRONG_DIRECTION_ERROR_MSG \ + "dsync backup: " \ + "Looks like you're trying to run backup in wrong direction. " \ + "Source is empty and destination is not." + static void dsync_brain_mailbox_list_deinit(struct dsync_brain_mailbox_list **list); static void @@ -290,6 +295,21 @@ dsync_brain_mailbox_action(struct dsync_brain *brain, } } +static bool +dsync_mailbox_list_is_empty(const ARRAY_TYPE(dsync_mailbox) *boxes_arr) +{ + struct dsync_mailbox *const *boxes; + unsigned int count; + + boxes = array_get(boxes_arr, &count); + if (count == 0) + return TRUE; + if (count == 1 && strcasecmp(boxes[0]->name, "INBOX") == 0 && + boxes[0]->message_count == 0) + return TRUE; + return FALSE; +} + static void dsync_brain_sync_mailboxes(struct dsync_brain *brain) { struct dsync_mailbox *const *src_boxes, *const *dest_boxes; @@ -300,6 +320,12 @@ static void dsync_brain_sync_mailboxes(struct dsync_brain *brain) bool src_deleted, dest_deleted; int ret; + if (brain->backup && + dsync_mailbox_list_is_empty(&brain->src_mailbox_list->mailboxes) && + !dsync_mailbox_list_is_empty(&brain->dest_mailbox_list->mailboxes)) { + i_fatal(DSYNC_WRONG_DIRECTION_ERROR_MSG); + } + /* create/delete missing mailboxes. the mailboxes are sorted by GUID, so we can do this quickly. */ src_boxes = array_get(&brain->src_mailbox_list->mailboxes, &src_count);