dovecot-1.2: istream-seekable: If we're immediately at EOF after...

dovecot at dovecot.org dovecot at dovecot.org
Tue Dec 22 21:20:04 EET 2009


details:   http://hg.dovecot.org/dovecot-1.2/rev/4e2134570b76
changeset: 9517:4e2134570b76
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Dec 22 14:04:15 2009 -0500
description:
istream-seekable: If we're immediately at EOF after copying buffer to file, don't corrupt the buffer.

diffstat:

1 file changed, 21 insertions(+), 2 deletions(-)
src/lib/istream-seekable.c |   23 +++++++++++++++++++++--

diffs (44 lines):

diff -r a1622da31bb1 -r 4e2134570b76 src/lib/istream-seekable.c
--- a/src/lib/istream-seekable.c	Tue Dec 22 14:02:10 2009 -0500
+++ b/src/lib/istream-seekable.c	Tue Dec 22 14:04:15 2009 -0500
@@ -72,7 +72,10 @@ i_stream_seekable_set_max_buffer_size(st
 
 static int copy_to_temp_file(struct seekable_istream *sstream)
 {
+	struct istream_private *stream = &sstream->istream;
 	const char *path;
+	const unsigned char *buffer;
+	size_t size;
 	int fd;
 
 	fd = sstream->fd_callback(&path, sstream->context);
@@ -89,11 +92,27 @@ static int copy_to_temp_file(struct seek
 	sstream->temp_path = i_strdup(path);
 	sstream->write_peak = sstream->buffer->used;
 
-	buffer_free(&sstream->buffer);
-
 	sstream->fd = fd;
 	sstream->fd_input =
 		i_stream_create_fd(fd, sstream->istream.max_buffer_size, TRUE);
+
+	/* read back the data we just had in our buffer */
+	i_stream_seek(sstream->fd_input, stream->istream.v_offset);
+	for (;;) {
+		buffer = i_stream_get_data(sstream->fd_input, &size);
+		if (size >= stream->pos)
+			break;
+
+		if (i_stream_read(sstream->fd_input) <= 0) {
+			i_error("istream-seekable: Couldn't read back "
+				"in-memory input");
+			i_stream_destroy(&sstream->fd_input);
+			return -1;
+		}
+	}
+	stream->buffer = buffer;
+	stream->pos = size;
+	buffer_free(&sstream->buffer);
 	return 0;
 }
 


More information about the dovecot-cvs mailing list