changeset 6160:fe1e6e895d8f HEAD

Delay writing to output file when saving messages until output buffer is full.
author Timo Sirainen <tss@iki.fi>
date Thu, 02 Aug 2007 17:35:04 +0300
parents 078d9dde99c8
children c62f7ee79446
files src/lib-storage/index/cydir/cydir-save.c src/lib-storage/index/maildir/maildir-save.c
diffstat 2 files changed, 17 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/cydir/cydir-save.c	Thu Aug 02 17:05:26 2007 +0300
+++ b/src/lib-storage/index/cydir/cydir-save.c	Thu Aug 02 17:35:04 2007 +0300
@@ -37,9 +37,9 @@
 
 static char *cydir_generate_tmp_filename(void)
 {
-	static unsigned int create_count;
+	static unsigned int create_count = 0;
 
-	return i_strdup_printf("%s.P%sQ%uM%s.%s",
+	return i_strdup_printf("temp.%s.P%sQ%uM%s.%s",
 			       dec2str(ioloop_timeval.tv_sec), my_pid,
 			       create_count++,
 			       dec2str(ioloop_timeval.tv_usec), my_hostname);
@@ -88,6 +88,7 @@
 		output = o_stream_create_file(ctx->fd, 0, FALSE);
 		ctx->output = o_stream_create_crlf(output);
 		o_stream_unref(&output);
+		o_stream_cork(ctx->output);
 
 		if (received_date != (time_t)-1) {
 			struct utimbuf ut;
@@ -169,6 +170,12 @@
 
 	ctx->finished = TRUE;
 
+	if (o_stream_flush(ctx->output) < 0) {
+		mail_storage_set_critical(storage,
+			"o_stream_flush(%s) failed: %m", path);
+		ctx->failed = TRUE;
+	}
+
 	if (!ctx->mbox->ibox.fsync_disable) {
 		if (fsync(ctx->fd) < 0) {
 			mail_storage_set_critical(storage,
--- a/src/lib-storage/index/maildir/maildir-save.c	Thu Aug 02 17:05:26 2007 +0300
+++ b/src/lib-storage/index/maildir/maildir-save.c	Thu Aug 02 17:35:04 2007 +0300
@@ -382,6 +382,7 @@
 		       MAIL_STORAGE_FLAG_SAVE_CRLF) != 0 ?
 		o_stream_create_crlf(output) : o_stream_create_lf(output);
 	o_stream_unref(&output);
+	o_stream_cork(ctx->output);
 
 	flags &= ~MAIL_RECENT;
 	if (mbox->ibox.keep_recent)
@@ -430,6 +431,13 @@
 	const char *path;
 	int output_errno;
 
+	if (o_stream_flush(ctx->output) < 0) {
+		mail_storage_set_critical(&ctx->mbox->storage->storage,
+			"o_stream_flush(%s/%s) failed: %m",
+			ctx->tmpdir, ctx->file_last->basename);
+		ctx->failed = TRUE;
+	}
+
 	if (ctx->cur_dest_mail != NULL) {
 		index_mail_cache_parse_deinit(ctx->cur_dest_mail);
 		i_stream_unref(&ctx->input);