Mercurial > dovecot > core-2.2
diff src/doveadm/dsync/dsync-brain.c @ 16801:56be613e8ece
dsync: Added -P parameter to do a purge for the remote storage after syncing.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 22 Sep 2013 01:09:32 +0300 |
parents | 0144704e1b99 |
children | add8c00fb3cc |
line wrap: on
line diff
--- a/src/doveadm/dsync/dsync-brain.c Sat Sep 21 23:33:42 2013 +0300 +++ b/src/doveadm/dsync/dsync-brain.c Sun Sep 22 01:09:32 2013 +0300 @@ -104,6 +104,7 @@ pool_t pool; service_set = master_service_settings_get(master_service); + mail_user_ref(user); pool = pool_alloconly_create("dsync brain", 10240); brain = p_new(pool, struct dsync_brain, 1); @@ -220,6 +221,23 @@ return brain; } +static void dsync_brain_purge(struct dsync_brain *brain) +{ + struct mail_namespace *ns; + struct mail_storage *storage; + + for (ns = brain->user->namespaces; ns != NULL; ns = ns->next) { + if (!dsync_brain_want_namespace(brain, ns)) + continue; + + storage = mail_namespace_get_default_storage(ns); + if (mail_storage_purge(storage) < 0) { + i_error("Purging namespace '%s' failed: %s", ns->prefix, + mail_storage_get_last_error(storage, NULL)); + } + } +} + int dsync_brain_deinit(struct dsync_brain **_brain) { struct dsync_brain *brain = *_brain; @@ -240,6 +258,9 @@ brain->failed = TRUE; dsync_ibc_close_mail_streams(brain->ibc); + if (brain->purge && !brain->failed) + dsync_brain_purge(brain); + if (brain->box != NULL) dsync_brain_sync_mailbox_deinit(brain); if (brain->local_tree_iter != NULL) @@ -261,6 +282,7 @@ } ret = brain->failed ? -1 : 0; + mail_user_unref(&brain->user); pool_unref(&brain->pool); return ret; } @@ -383,7 +405,11 @@ sizeof(brain->sync_box_guid)); i_assert(brain->sync_type == DSYNC_BRAIN_SYNC_TYPE_UNKNOWN); brain->sync_type = ibc_set->sync_type; + dsync_brain_set_flags(brain, ibc_set->brain_flags); + /* this flag is only set on the remote slave brain */ + brain->purge = (ibc_set->brain_flags & + DSYNC_BRAIN_FLAG_PURGE_REMOTE) != 0; dsync_brain_mailbox_trees_init(brain);