dovecot-2.2: dsync: Fixed infinite loop in importer.

dovecot at dovecot.org dovecot at dovecot.org
Sun Feb 17 10:15:10 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/e7396c0f7f66
changeset: 15820:e7396c0f7f66
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Feb 17 10:15:04 2013 +0200
description:
dsync: Fixed infinite loop in importer.

diffstat:

 src/doveadm/dsync/dsync-mailbox-import.c |  28 +++++++++++++++++++++++-----
 1 files changed, 23 insertions(+), 5 deletions(-)

diffs (41 lines):

diff -r 9c095a50ba3e -r e7396c0f7f66 src/doveadm/dsync/dsync-mailbox-import.c
--- a/src/doveadm/dsync/dsync-mailbox-import.c	Sun Feb 17 10:14:49 2013 +0200
+++ b/src/doveadm/dsync/dsync-mailbox-import.c	Sun Feb 17 10:15:04 2013 +0200
@@ -1305,14 +1305,32 @@
 				uint32_t wanted_uid)
 {
 	const struct seq_range *range;
-	unsigned int count;
+	unsigned int count, n;
+	struct seq_range_iter iter;
+	uint32_t uid;
 
-	while ((count = array_count(unwanted_uids)) > 0) {
-		range = array_idx(unwanted_uids, count-1);
-		if (dsync_msg_change_uid(importer, range->seq2, wanted_uid)) {
-			seq_range_array_remove(unwanted_uids, range->seq2);
+	/* optimize by first trying to use the latest UID */
+	range = array_get(unwanted_uids, &count);
+	if (count == 0)
+		return FALSE;
+	if (dsync_msg_change_uid(importer, range[count-1].seq2, wanted_uid)) {
+		seq_range_array_remove(unwanted_uids, range[count-1].seq2);
+		return TRUE;
+	}
+	if (mailbox_get_last_mail_error(importer->box) == MAIL_ERROR_EXPUNGED)
+		seq_range_array_remove(unwanted_uids, range[count-1].seq2);
+
+	/* now try to use any of them by iterating through them. (would be
+	   easier&faster to just iterate backwards, but probably too much
+	   trouble to add such API) */
+	n = 0; seq_range_array_iter_init(&iter, unwanted_uids);
+	while (seq_range_array_iter_nth(&iter, n++, &uid)) {
+		if (dsync_msg_change_uid(importer, uid, wanted_uid)) {
+			seq_range_array_remove(unwanted_uids, uid);
 			return TRUE;
 		}
+		if (mailbox_get_last_mail_error(importer->box) == MAIL_ERROR_EXPUNGED)
+			seq_range_array_remove(unwanted_uids, uid);
 	}
 	return FALSE;
 }


More information about the dovecot-cvs mailing list