changeset 1371:b73c2bdd12d0 HEAD

fsync() saved mails
author Timo Sirainen <tss@iki.fi>
date Mon, 21 Apr 2003 18:41:19 +0300
parents 5f521a721671
children 7a7e58744e0a
files src/lib-storage/index/maildir/maildir-save.c src/lib-storage/index/mbox/mbox-save.c
diffstat 2 files changed, 16 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/maildir/maildir-save.c	Mon Apr 21 16:42:00 2003 +0300
+++ b/src/lib-storage/index/maildir/maildir-save.c	Mon Apr 21 18:41:19 2003 +0300
@@ -53,8 +53,18 @@
 		fname = NULL;
 
 	o_stream_unref(output);
-	if (close(fd) < 0)
+	/* FIXME: when saving multiple messages, we could get better
+	   performance if we left the fd open and fsync()ed it later */
+	if (fsync(fd) < 0) {
+		mail_storage_set_critical(ibox->box.storage,
+					  "fsync() failed for %s: %m", path);
 		fname = NULL;
+	}
+	if (close(fd) < 0) {
+		mail_storage_set_critical(ibox->box.storage,
+					  "close() failed for %s: %m", path);
+		fname = NULL;
+	}
 
 	if (fname == NULL)
 		(void)unlink(path);
--- a/src/lib-storage/index/mbox/mbox-save.c	Mon Apr 21 16:42:00 2003 +0300
+++ b/src/lib-storage/index/mbox/mbox-save.c	Mon Apr 21 18:41:19 2003 +0300
@@ -357,6 +357,11 @@
 			syscall_error(ctx, "ftruncate()");
 			failed = TRUE;
 		}
+	} else {
+		if (fdatasync(ctx->ibox->index->mbox_fd) < 0) {
+			syscall_error(ctx, "fsync()");
+			failed = TRUE;
+		}
 	}
 
 	i_free(ctx);