dovecot-2.2: lib-fs: istream-metawrap supports now seeking befor...

dovecot at dovecot.org dovecot at dovecot.org
Tue Mar 5 12:20:52 EET 2013


details:   http://hg.dovecot.org/dovecot-2.2/rev/3dcdbab51347
changeset: 15996:3dcdbab51347
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Mar 05 12:20:41 2013 +0200
description:
lib-fs: istream-metawrap supports now seeking before reading the metadata.

diffstat:

 src/lib-fs/istream-metawrap.c |  20 ++++++++++++++------
 1 files changed, 14 insertions(+), 6 deletions(-)

diffs (44 lines):

diff -r bdca6ecb5bb4 -r 3dcdbab51347 src/lib-fs/istream-metawrap.c
--- a/src/lib-fs/istream-metawrap.c	Tue Mar 05 11:45:26 2013 +0200
+++ b/src/lib-fs/istream-metawrap.c	Tue Mar 05 12:20:41 2013 +0200
@@ -9,7 +9,7 @@
 	metawrap_callback_t *callback;
 	void *context;
 
-	uoff_t start_offset;
+	uoff_t start_offset, pending_seek;
 	bool in_metadata;
 };
 
@@ -57,6 +57,10 @@
 		/* this stream is kind of silently skipping over the metadata */
 		stream->abs_start_offset += mstream->start_offset;
 		mstream->in_metadata = FALSE;
+		if (mstream->pending_seek != 0) {
+			i_stream_seek(&stream->istream, mstream->pending_seek);
+			return i_stream_read(&stream->istream);
+		}
 	}
 	/* after metadata header it's all just passthrough */
 	return i_stream_read_copy_from_parent(&stream->istream);
@@ -68,11 +72,15 @@
 {
 	struct metawrap_istream *mstream = (struct metawrap_istream *)stream;
 
-	/* support seeking only after reading the metadata */
-	i_assert(!mstream->in_metadata ||
-		 (mstream->start_offset == 0 && v_offset == 0));
-
-	stream->istream.v_offset = v_offset;
+	if (!mstream->in_metadata) {
+		/* already read through metadata. we can skip directly. */
+		stream->istream.v_offset = v_offset;
+		mstream->pending_seek = 0;
+	} else {
+		/* we need to read through the metadata first */
+		mstream->pending_seek = v_offset;
+		stream->istream.v_offset = 0;
+	}
 	stream->skip = stream->pos = 0;
 }
 


More information about the dovecot-cvs mailing list