dovecot-2.0: dsync backup: Fail if it looks like backup is runni...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Jul 5 14:35:56 EEST 2010
details: http://hg.dovecot.org/dovecot-2.0/rev/42dfcf9c896b
changeset: 11727:42dfcf9c896b
user: Timo Sirainen <tss at iki.fi>
date: Mon Jul 05 12:35:52 2010 +0100
description:
dsync backup: Fail if it looks like backup is running in wrong direction.
diffstat:
src/dsync/dsync-brain.c | 26 ++++++++++++++++++++++++++
1 files changed, 26 insertions(+), 0 deletions(-)
diffs (50 lines):
diff -r 18bebc4faa6b -r 42dfcf9c896b src/dsync/dsync-brain.c
--- a/src/dsync/dsync-brain.c Mon Jul 05 12:34:11 2010 +0100
+++ b/src/dsync/dsync-brain.c Mon Jul 05 12:35:52 2010 +0100
@@ -9,6 +9,11 @@
#include <unistd.h>
+#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 @@
}
}
+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 @@
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);
More information about the dovecot-cvs
mailing list