changeset 2986:51a05fd00324 HEAD

Named pipes are now treated as write-only mboxes.
author Timo Sirainen <tss@iki.fi>
date Fri, 17 Dec 2004 02:05:54 +0200
parents f1e67917a669
children d1a2c39d1b50
files src/lib-storage/index/mbox/mbox-file.c src/lib-storage/index/mbox/mbox-save.c src/lib-storage/index/mbox/mbox-sync.c
diffstat 3 files changed, 20 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/mbox/mbox-file.c	Thu Dec 16 22:41:15 2004 +0200
+++ b/src/lib-storage/index/mbox/mbox-file.c	Fri Dec 17 02:05:54 2004 +0200
@@ -33,6 +33,7 @@
 		return -1;
 	}
 
+	ibox->mbox_writeonly = S_ISFIFO(st.st_mode);
 	ibox->mbox_fd = fd;
 	ibox->mbox_dev = st.st_dev;
 	ibox->mbox_ino = st.st_ino;
@@ -62,7 +63,10 @@
 			return -1;
 	}
 
-	if (ibox->mail_read_mmaped) {
+	if (ibox->mbox_writeonly) {
+		ibox->mbox_file_stream =
+			i_stream_create_from_data(default_pool, NULL, 0);
+	} else if (ibox->mail_read_mmaped) {
 		ibox->mbox_file_stream =
 			i_stream_create_mmap(ibox->mbox_fd, default_pool,
 					     MAIL_MMAP_BLOCK_SIZE,
--- a/src/lib-storage/index/mbox/mbox-save.c	Thu Dec 16 22:41:15 2004 +0200
+++ b/src/lib-storage/index/mbox/mbox-save.c	Fri Dec 17 02:05:54 2004 +0200
@@ -68,6 +68,11 @@
 	char ch;
 	int fd;
 
+	if (ctx->ibox->mbox_writeonly) {
+		*offset = 0;
+		return 0;
+	}
+
 	fd = ctx->ibox->mbox_fd;
 	if (fstat(fd, &st) < 0)
                 return mbox_set_syscall_error(ctx->ibox, "fstat()");
@@ -146,6 +151,11 @@
 	size_t len;
 	int ret = 0;
 
+	if (ctx->ibox->mbox_writeonly) {
+		/* we can't seek, don't set Content-Length */
+		return 0;
+	}
+
 	end_offset = ctx->output->offset;
 
 	/* write Content-Length headers */
@@ -541,9 +551,10 @@
 			&ctx->next_uid, sizeof(ctx->next_uid));
 	}
 
-	if (!ctx->synced && ctx->ibox->mbox_fd != -1) {
+	if (!ctx->synced && ctx->ibox->mbox_fd != -1 &&
+	    !ctx->ibox->mbox_writeonly) {
 		if (fdatasync(ctx->ibox->mbox_fd) < 0) {
-			mbox_set_syscall_error(ctx->ibox, "fsync()");
+			mbox_set_syscall_error(ctx->ibox, "fdatasync()");
 			ret = -1;
 		}
 	}
--- a/src/lib-storage/index/mbox/mbox-sync.c	Thu Dec 16 22:41:15 2004 +0200
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Fri Dec 17 02:05:54 2004 +0200
@@ -1403,7 +1403,8 @@
 		}
 	}
 
-	if (ret == 0 && ibox->mbox_lock_type == F_WRLCK) {
+	if (ret == 0 && ibox->mbox_lock_type == F_WRLCK &&
+	    !ibox->mbox_writeonly) {
 		if (fsync(ibox->mbox_fd) < 0) {
 			mbox_set_syscall_error(ibox, "fsync()");
 			ret = -1;