[dovecot-cvs] dovecot/src/lib-storage/index/dbox dbox-save.c, 1.7, 1.8

cras at dovecot.org cras at dovecot.org
Wed Apr 12 21:43:54 EEST 2006


Update of /var/lib/cvs/dovecot/src/lib-storage/index/dbox
In directory talvi:/tmp/cvs-serv19531

Modified Files:
	dbox-save.c 
Log Message:
Truncate dbox file immediately if saving is aborted.



Index: dbox-save.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/dbox/dbox-save.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- dbox-save.c	12 Apr 2006 16:51:38 -0000	1.7
+++ dbox-save.c	12 Apr 2006 18:43:52 -0000	1.8
@@ -248,15 +248,16 @@
 	struct dbox_mail_header hdr;
 
 	ctx->finished = TRUE;
-	if (!ctx->failed) {
-		/* make sure the file ends here (we could have been
-		   overwriting some existing aborted mail) */
-		if (ftruncate(ctx->file->fd, ctx->file->output->offset) < 0) {
-			mail_storage_set_critical(STORAGE(ctx->mbox->storage),
-						  "ftruncate(%s) failed: %m",
-						  ctx->file->path);
-			ctx->failed = TRUE;
-		}
+
+	/* Make sure the file ends here (we could have been overwriting some
+	   existing aborted mail). In case we failed, truncate the file to
+	   the size before writing. */
+	if (ftruncate(ctx->file->fd, ctx->failed ? ctx->hdr_offset :
+		      ctx->file->output->offset) < 0) {
+		mail_storage_set_critical(STORAGE(ctx->mbox->storage),
+					  "ftruncate(%s) failed: %m",
+					  ctx->file->path);
+		ctx->failed = TRUE;
 	}
 
 	if (!ctx->failed) {



More information about the dovecot-cvs mailing list