Mercurial > dovecot > core-2.2
changeset 15257:60f0cb48fdb2
doveadm backup: Revert all local changes.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 24 Oct 2012 15:05:40 +0300 |
parents | ce3f3006383b |
children | 67af7122a522 |
files | src/doveadm/dsync/dsync-brain-mailbox.c src/doveadm/dsync/dsync-mailbox-import.c src/doveadm/dsync/dsync-mailbox-import.h |
diffstat | 3 files changed, 51 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- 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,
--- 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) {
--- 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;