dovecot-2.0: dbox: Allow getting streams to messages being saved.

dovecot at dovecot.org dovecot at dovecot.org
Mon Sep 7 01:53:34 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/af8424c95825
changeset: 9885:af8424c95825
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Sep 06 18:53:24 2009 -0400
description:
dbox: Allow getting streams to messages being saved.

diffstat:

3 files changed, 44 insertions(+), 1 deletion(-)
src/lib-storage/index/dbox/dbox-mail.c    |   12 +++++++++++-
src/lib-storage/index/dbox/dbox-save.c    |   29 +++++++++++++++++++++++++++++
src/lib-storage/index/dbox/dbox-storage.h |    4 ++++

diffs (87 lines):

diff -r 38fbf201824c -r af8424c95825 src/lib-storage/index/dbox/dbox-mail.c
--- a/src/lib-storage/index/dbox/dbox-mail.c	Sun Sep 06 17:20:04 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-mail.c	Sun Sep 06 18:53:24 2009 -0400
@@ -143,12 +143,22 @@ static int dbox_mail_open(struct dbox_ma
 		return mail_set_aborted(_mail);
 
 	do {
-		if (mail->open_file == NULL) {
+		if (mail->open_file != NULL) {
+			/* already open */
+		} else if (_mail->uid != 0) {
 			if (dbox_mail_lookup(mbox, mbox->ibox.view, _mail->seq,
 					     &mail->map_uid) < 0)
 				return -1;
 			if (dbox_mail_open_init(mail) < 0)
 				return -1;
+		} else {
+			/* mail is being saved in this transaction */
+			mail->open_file =
+				dbox_save_file_get_file(_mail->transaction,
+							_mail->seq,
+							&mail->offset);
+			mail->open_file->refcount++;
+			break;
 		}
 
 		if (!dbox_file_is_open(mail->open_file))
diff -r 38fbf201824c -r af8424c95825 src/lib-storage/index/dbox/dbox-save.c
--- a/src/lib-storage/index/dbox/dbox-save.c	Sun Sep 06 17:20:04 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-save.c	Sun Sep 06 18:53:24 2009 -0400
@@ -53,6 +53,30 @@ struct dbox_save_context {
 	unsigned int finished:1;
 };
 
+struct dbox_file *
+dbox_save_file_get_file(struct mailbox_transaction_context *t,
+			uint32_t seq, uoff_t *offset_r)
+{
+	struct dbox_save_context *ctx = (struct dbox_save_context *)t->save_ctx;
+	const struct dbox_save_mail *mails, *mail;
+	unsigned int count;
+
+	mails = array_get(&ctx->mails, &count);
+	i_assert(count > 0);
+	i_assert(seq >= mails[0].seq);
+
+	mail = &mails[mails[0].seq - seq];
+	i_assert(mail->seq == seq);
+
+	if (o_stream_flush(mail->file->output) < 0) {
+		dbox_file_set_syscall_error(mail->file, "write()");
+		ctx->failed = TRUE;
+	}
+
+	*offset_r = mail->append_offset;
+	return mail->file;
+}
+
 struct mail_save_context *
 dbox_save_alloc(struct mailbox_transaction_context *t)
 {
@@ -275,6 +299,11 @@ static int dbox_save_finish_write(struct
 			ctx->failed = TRUE;
 	} T_END;
 
+	if (o_stream_flush(ctx->cur_output) < 0) {
+		dbox_file_set_syscall_error(save_mail->file, "write()");
+		ctx->failed = TRUE;
+	}
+
 	o_stream_unref(&ctx->cur_output);
 	i_stream_unref(&ctx->input);
 
diff -r 38fbf201824c -r af8424c95825 src/lib-storage/index/dbox/dbox-storage.h
--- a/src/lib-storage/index/dbox/dbox-storage.h	Sun Sep 06 17:20:04 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-storage.h	Sun Sep 06 18:53:24 2009 -0400
@@ -110,6 +110,10 @@ int dbox_save_finish(struct mail_save_co
 int dbox_save_finish(struct mail_save_context *ctx);
 void dbox_save_cancel(struct mail_save_context *ctx);
 
+struct dbox_file *
+dbox_save_file_get_file(struct mailbox_transaction_context *t,
+			uint32_t seq, uoff_t *offset_r);
+
 int dbox_transaction_save_commit_pre(struct mail_save_context *ctx);
 void dbox_transaction_save_commit_post(struct mail_save_context *ctx);
 void dbox_transaction_save_rollback(struct mail_save_context *ctx);


More information about the dovecot-cvs mailing list