From: Timo Sirainen Date: Wed, 5 Jun 2013 14:14:49 +0000 (+0300) Subject: dsync: If unexpected changes happened during sync, log a warning and exit with code 2. X-Git-Tag: 2.2.3~69 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=f40c798116d0b1d735d5eeb8db3dc2022e7e064d;p=thirdparty%2Fdovecot%2Fcore.git dsync: If unexpected changes happened during sync, log a warning and exit with code 2. This was done by v2.1 dsync, but the code got temporarily lost in v2.2. --- diff --git a/src/doveadm/dsync/doveadm-dsync.c b/src/doveadm/dsync/doveadm-dsync.c index a1e6e9d8b3..4957a3c57e 100644 --- a/src/doveadm/dsync/doveadm-dsync.c +++ b/src/doveadm/dsync/doveadm-dsync.c @@ -291,7 +291,8 @@ static bool paths_are_equal(struct mail_user *user1, struct mail_user *user2, static int cmd_dsync_run_local(struct dsync_cmd_context *ctx, struct mail_user *user, - struct dsync_brain *brain, struct dsync_ibc *ibc2) + struct dsync_brain *brain, struct dsync_ibc *ibc2, + bool *changes_during_sync_r) { struct dsync_brain *brain2; struct mail_user *user2; @@ -357,6 +358,7 @@ cmd_dsync_run_local(struct dsync_cmd_context *ctx, struct mail_user *user, brain2_running = dsync_brain_run(brain2, &changed2); } mail_user_unref(&user2); + *changes_during_sync_r = dsync_brain_has_unexpected_changes(brain2); if (dsync_brain_deinit(&brain2) < 0) { ctx->ctx.exit_code = EX_TEMPFAIL; return -1; @@ -490,6 +492,7 @@ cmd_dsync_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) struct dsync_brain_settings set; enum dsync_brain_flags brain_flags; bool remote_errors_logged = FALSE; + bool changes_during_sync = FALSE; int status = 0, ret = 0; memset(&set, 0, sizeof(set)); @@ -540,7 +543,8 @@ cmd_dsync_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) brain_flags, &set); if (ctx->run_type == DSYNC_RUN_TYPE_LOCAL) { - if (cmd_dsync_run_local(ctx, user, brain, ibc2) < 0) + if (cmd_dsync_run_local(ctx, user, brain, ibc2, + &changes_during_sync) < 0) ret = -1; } else { cmd_dsync_run_remote(user); @@ -552,6 +556,11 @@ cmd_dsync_run(struct doveadm_mail_cmd_context *_ctx, struct mail_user *user) doveadm_print(str_c(state_str)); } + if (dsync_brain_has_unexpected_changes(brain) || changes_during_sync) { + i_warning("Mailbox changes caused a desync. " + "You may want to run dsync again."); + ctx->ctx.exit_code = 2; + } if (dsync_brain_deinit(&brain) < 0) { ctx->ctx.exit_code = EX_TEMPFAIL; ret = -1; diff --git a/src/doveadm/dsync/dsync-brain.c b/src/doveadm/dsync/dsync-brain.c index 803c44725d..a6b4bd4c0c 100644 --- a/src/doveadm/dsync/dsync-brain.c +++ b/src/doveadm/dsync/dsync-brain.c @@ -513,3 +513,8 @@ bool dsync_brain_has_failed(struct dsync_brain *brain) { return brain->failed; } + +bool dsync_brain_has_unexpected_changes(struct dsync_brain *brain) +{ + return brain->changes_during_sync; +} diff --git a/src/doveadm/dsync/dsync-brain.h b/src/doveadm/dsync/dsync-brain.h index 6d7c218742..c280908f3e 100644 --- a/src/doveadm/dsync/dsync-brain.h +++ b/src/doveadm/dsync/dsync-brain.h @@ -67,5 +67,7 @@ bool dsync_brain_has_failed(struct dsync_brain *brain); void dsync_brain_get_state(struct dsync_brain *brain, string_t *output); /* Returns the sync type that was used. Mainly useful with slave brain. */ enum dsync_brain_sync_type dsync_brain_get_sync_type(struct dsync_brain *brain); +/* Returns TRUE if there were any unexpected changes during the sync. */ +bool dsync_brain_has_unexpected_changes(struct dsync_brain *brain); #endif