dovecot-2.0: dsync backup: Handle better deletion of mailboxes f...

dovecot at dovecot.org dovecot at dovecot.org
Thu Mar 24 00:01:18 EET 2011


details:   http://hg.dovecot.org/dovecot-2.0/rev/65f4791d0eb4
changeset: 12699:65f4791d0eb4
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Mar 24 00:01:16 2011 +0200
description:
dsync backup: Handle better deletion of mailboxes from destination.

diffstat:

 src/dsync/dsync-worker-local.c |  35 +++++++++++++++++++++++++----------
 1 files changed, 25 insertions(+), 10 deletions(-)

diffs (96 lines):

diff -r a5f9264674fb -r 65f4791d0eb4 src/dsync/dsync-worker-local.c
--- a/src/dsync/dsync-worker-local.c	Wed Mar 23 23:13:00 2011 +0200
+++ b/src/dsync/dsync-worker-local.c	Thu Mar 24 00:01:16 2011 +0200
@@ -49,6 +49,7 @@
 	struct mail_namespace *ns;
 	mailbox_guid_t guid;
 	const char *storage_name;
+	bool deleted;
 };
 
 struct local_dsync_mailbox_change {
@@ -797,6 +798,10 @@
 			dsync_guid_to_str(guid));
 		return -1;
 	}
+	if (lbox->deleted) {
+		*box_r = NULL;
+		return 0;
+	}
 
 	box = mailbox_alloc(lbox->ns->list, lbox->storage_name, flags);
 	if (mailbox_sync(box, 0) < 0 ||
@@ -817,7 +822,7 @@
 		return -1;
 	}
 	*box_r = box;
-	return 0;
+	return 1;
 }
 
 static int iter_local_mailbox_open(struct local_dsync_worker_msg_iter *iter)
@@ -828,14 +833,22 @@
 	struct mailbox *box;
 	struct mailbox_transaction_context *trans;
 	struct mail_search_args *search_args;
+	int ret;
 
-	if (iter->mailbox_idx == iter->mailbox_count) {
-		/* no more mailboxes */
-		return -1;
+	for (;;) {
+		if (iter->mailbox_idx == iter->mailbox_count) {
+			/* no more mailboxes */
+			return -1;
+		}
+
+		guid = &iter->mailboxes[iter->mailbox_idx];
+		ret = local_mailbox_open(worker, guid, &box);
+		if (ret != 0)
+			break;
+		/* mailbox was deleted. try next one. */
+		iter->mailbox_idx++;
 	}
-
-	guid = &iter->mailboxes[iter->mailbox_idx];
-	if (local_mailbox_open(worker, guid, &box) < 0) {
+	if (ret < 0) {
 		i_error("msg iteration failed: Couldn't open mailbox %s",
 			dsync_guid_to_str(guid));
 		iter->iter.failed = TRUE;
@@ -1282,6 +1295,8 @@
 		i_error("Can't delete mailbox %s: %s", lbox->storage_name,
 			mail_storage_get_last_error(storage, NULL));
 		dsync_worker_set_failure(_worker);
+	} else {
+		lbox->deleted = TRUE;
 	}
 	mailbox_free(&box);
 	mailbox_list_set_changelog_timestamp(lbox->ns->list, (time_t)-1);
@@ -1492,7 +1507,7 @@
 		local_worker_mailbox_close(worker);
 	worker->selected_box_guid = *mailbox;
 
-	if (local_mailbox_open(worker, mailbox, &worker->selected_box) < 0) {
+	if (local_mailbox_open(worker, mailbox, &worker->selected_box) <= 0) {
 		dsync_worker_set_failure(_worker);
 		return;
 	}
@@ -1601,7 +1616,7 @@
 	struct mail_save_context *save_ctx;
 	int ret;
 
-	if (local_mailbox_open(worker, src_mailbox, &src_box) < 0) {
+	if (local_mailbox_open(worker, src_mailbox, &src_box) <= 0) {
 		callback(FALSE, context);
 		return;
 	}
@@ -1793,7 +1808,7 @@
 
 	if (!dsync_guid_equals(&worker->get_mailbox, &get->mailbox)) {
 		local_worker_msg_box_close(worker);
-		if (local_mailbox_open(worker, &get->mailbox, &box) < 0) {
+		if (local_mailbox_open(worker, &get->mailbox, &box) <= 0) {
 			get->callback(DSYNC_MSG_GET_RESULT_FAILED,
 				      NULL, get->context);
 			return;


More information about the dovecot-cvs mailing list