From: Timo Sirainen Date: Tue, 2 Oct 2012 22:26:42 +0000 (+0300) Subject: mdbox: Fix to handling transactions with partially failed saves. X-Git-Tag: 2.2.alpha1~20^2~41 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60f5757c647cb65d0be79ef6e853d3cb0e2eb047;p=thirdparty%2Fdovecot%2Fcore.git mdbox: Fix to handling transactions with partially failed saves. --- diff --git a/src/lib-storage/index/dbox-common/dbox-file.c b/src/lib-storage/index/dbox-common/dbox-file.c index a7c4178eac..61d9fcdfbe 100644 --- a/src/lib-storage/index/dbox-common/dbox-file.c +++ b/src/lib-storage/index/dbox-common/dbox-file.c @@ -532,7 +532,8 @@ int dbox_file_append_flush(struct dbox_file_append_context *ctx) { struct mail_storage *storage = &ctx->file->storage->storage; - if (ctx->last_flush_offset == ctx->output->offset) + if (ctx->last_flush_offset == ctx->output->offset && + ctx->last_checkpoint_offset == ctx->output->offset) return 0; if (o_stream_flush(ctx->output) < 0) { @@ -540,6 +541,14 @@ int dbox_file_append_flush(struct dbox_file_append_context *ctx) return -1; } + if (ctx->last_checkpoint_offset != ctx->output->offset) { + if (ftruncate(ctx->file->fd, ctx->last_checkpoint_offset) < 0) { + dbox_file_set_syscall_error(ctx->file, "ftruncate()"); + return -1; + } + o_stream_seek(ctx->output, ctx->last_checkpoint_offset); + } + if (storage->set->parsed_fsync_mode != FSYNC_MODE_NEVER) { if (fdatasync(ctx->file->fd) < 0) { dbox_file_set_syscall_error(ctx->file, "fdatasync()");