diff src/lib-storage/index/dbox-common/dbox-file.c @ 15337:1b46c1bf9d1e

Merged changes from v2.1 tree.
author Timo Sirainen <tss@iki.fi>
date Mon, 29 Oct 2012 17:55:35 +0200
parents d0d7b810646b 19732dd98602
children f06419a40a06
line wrap: on
line diff
--- a/src/lib-storage/index/dbox-common/dbox-file.c	Mon Oct 29 16:51:46 2012 +0200
+++ b/src/lib-storage/index/dbox-common/dbox-file.c	Mon Oct 29 17:55:35 2012 +0200
@@ -534,7 +534,8 @@
 {
 	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_nfinish(ctx->output) < 0) {
@@ -542,6 +543,14 @@
 		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()");