]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Fix to handling transactions with partially failed saves.
authorTimo Sirainen <tss@iki.fi>
Tue, 2 Oct 2012 22:26:42 +0000 (01:26 +0300)
committerTimo Sirainen <tss@iki.fi>
Tue, 2 Oct 2012 22:26:42 +0000 (01:26 +0300)
src/lib-storage/index/dbox-common/dbox-file.c

index a7c4178eacbe1c95e7c1bbf5b45fd9f0a628163f..61d9fcdfbe11e570374ca668dc7b705fc4876e57 100644 (file)
@@ -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()");