dovecot-2.2: doveadm backup: Revert all local changes.

dovecot at dovecot.org dovecot at dovecot.org
Fri Oct 26 10:36:55 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/60f0cb48fdb2
changeset: 15257:60f0cb48fdb2
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Oct 24 15:05:40 2012 +0300
description:
doveadm backup: Revert all local changes.

diffstat:

 src/doveadm/dsync/dsync-brain-mailbox.c  |   2 +
 src/doveadm/dsync/dsync-mailbox-import.c |  47 ++++++++++++++++++++++++++++++++
 src/doveadm/dsync/dsync-mailbox-import.h |   3 +-
 3 files changed, 51 insertions(+), 1 deletions(-)

diffs (103 lines):

diff -r ce3f3006383b -r 60f0cb48fdb2 src/doveadm/dsync/dsync-brain-mailbox.c
--- a/src/doveadm/dsync/dsync-brain-mailbox.c	Wed Oct 24 15:05:15 2012 +0300
+++ b/src/doveadm/dsync/dsync-brain-mailbox.c	Wed Oct 24 15:05:40 2012 +0300
@@ -195,6 +195,8 @@
 		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_MASTER_BRAIN;
 	if (brain->mails_have_guids)
 		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS;
+	if (brain->backup_recv)
+		import_flags |= DSYNC_MAILBOX_IMPORT_FLAG_REVERT_LOCAL_CHANGES;
 
 	brain->box_importer = brain->backup_send ? NULL :
 		dsync_mailbox_import_init(brain->box, brain->log_scan,
diff -r ce3f3006383b -r 60f0cb48fdb2 src/doveadm/dsync/dsync-mailbox-import.c
--- a/src/doveadm/dsync/dsync-mailbox-import.c	Wed Oct 24 15:05:15 2012 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-import.c	Wed Oct 24 15:05:40 2012 +0300
@@ -81,6 +81,7 @@
 	unsigned int want_mail_requests:1;
 	unsigned int mails_have_guids:1;
 	unsigned int master_brain:1;
+	unsigned int revert_local_changes:1;
 };
 
 static void
@@ -158,6 +159,8 @@
 		(flags & DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS) != 0;
 	importer->master_brain =
 		(flags & DSYNC_MAILBOX_IMPORT_FLAG_MASTER_BRAIN) != 0;
+	importer->revert_local_changes =
+		(flags & DSYNC_MAILBOX_IMPORT_FLAG_REVERT_LOCAL_CHANGES) != 0;
 
 	mailbox_get_open_status(importer->box,
 				STATUS_UIDNEXT | STATUS_HIGHESTMODSEQ,
@@ -635,6 +638,44 @@
 }
 
 static void
+dsync_mailbox_import_replace_flags(struct mail *mail,
+				   const struct dsync_mail_change *change)
+{
+	ARRAY_TYPE(const_string) keywords;
+	struct mail_keywords *kw;
+	const char *const *changes, *name;
+	unsigned int i, count;
+
+	if (array_is_created(&change->keyword_changes))
+		changes = array_get(&change->keyword_changes, &count);
+	else {
+		changes = NULL;
+		count = 0;
+	}
+	t_array_init(&keywords, count+1);
+	for (i = 0; i < count; i++) {
+		switch (changes[i][0]) {
+		case KEYWORD_CHANGE_ADD:
+		case KEYWORD_CHANGE_FINAL:
+			name = changes[i]+1;
+			array_append(&keywords, &name, 1);
+			break;
+		case KEYWORD_CHANGE_REMOVE:
+			break;
+		}
+	}
+	array_append_zero(&keywords);
+
+	kw = mailbox_keywords_create_valid(mail->box, array_idx(&keywords, 0));
+	mail_update_keywords(mail, MODIFY_REPLACE, kw);
+	mailbox_keywords_unref(&kw);
+
+	mail_update_flags(mail, MODIFY_REPLACE,
+			  change->add_flags | change->final_flags);
+	mail_update_modseq(mail, change->modseq);
+}
+
+static void
 dsync_mailbox_import_flag_change(struct dsync_mailbox_importer *importer,
 				 const struct dsync_mail_change *change)
 {
@@ -656,6 +697,12 @@
 		mail = importer->mail;
 	}
 
+	if (importer->revert_local_changes) {
+		/* dsync backup: just make the local look like remote. */
+		dsync_mailbox_import_replace_flags(mail, change);
+		return;
+	}
+
 	local_change = hash_table_lookup(importer->local_changes,
 					 POINTER_CAST(change->uid));
 	if (local_change == NULL) {
diff -r ce3f3006383b -r 60f0cb48fdb2 src/doveadm/dsync/dsync-mailbox-import.h
--- a/src/doveadm/dsync/dsync-mailbox-import.h	Wed Oct 24 15:05:15 2012 +0300
+++ b/src/doveadm/dsync/dsync-mailbox-import.h	Wed Oct 24 15:05:40 2012 +0300
@@ -4,7 +4,8 @@
 enum dsync_mailbox_import_flags {
 	DSYNC_MAILBOX_IMPORT_FLAG_MASTER_BRAIN		= 0x01,
 	DSYNC_MAILBOX_IMPORT_FLAG_WANT_MAIL_REQUESTS	= 0x02,
-	DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS	= 0x04
+	DSYNC_MAILBOX_IMPORT_FLAG_MAILS_HAVE_GUIDS	= 0x04,
+	DSYNC_MAILBOX_IMPORT_FLAG_REVERT_LOCAL_CHANGES	= 0x08
 };
 
 struct mailbox;


More information about the dovecot-cvs mailing list