Mercurial > dovecot > core-2.2
changeset 4327:dbae2347dcdb HEAD
Handle i_stream_stat() better.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Thu, 08 Jun 2006 22:26:53 +0300 |
parents | e228a9efd35d |
children | 79e7c206a75c |
files | src/lib-mail/istream-header-filter.c src/lib-storage/index/mbox/istream-raw-mbox.c |
diffstat | 2 files changed, 37 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-mail/istream-header-filter.c Thu Jun 08 21:52:40 2006 +0300 +++ b/src/lib-mail/istream-header-filter.c Thu Jun 08 22:26:53 2006 +0300 @@ -235,21 +235,26 @@ return ret; } +static void parse_header(struct header_filter_istream *mstream) +{ + size_t pos; + + while (!mstream->header_read) { + if (_read(&mstream->istream) == -1) + break; + + (void)i_stream_get_data(&mstream->istream.istream, &pos); + i_stream_skip(&mstream->istream.istream, pos); + } +} + static void _seek(struct _istream *stream, uoff_t v_offset, bool mark __attr_unused__) { struct header_filter_istream *mstream = (struct header_filter_istream *)stream; - size_t pos; - while (!mstream->header_read) { - if (_read(stream) == -1) - break; - - (void)i_stream_get_data(&stream->istream, &pos); - i_stream_skip(&stream->istream, pos); - } - + parse_header(mstream); stream->istream.v_offset = v_offset; stream->skip = stream->pos = 0; stream->buffer = NULL; @@ -280,9 +285,22 @@ } static const struct stat * -_stat(struct _istream *stream, bool exact __attr_unused__) +_stat(struct _istream *stream, bool exact) { - /* return size and others as unknown */ + struct header_filter_istream *mstream = + (struct header_filter_istream *)stream; + const struct stat *st; + + st = i_stream_stat(mstream->input, exact); + if (st == NULL || st->st_size == -1 || !exact) + return st; + + parse_header(mstream); + + stream->statbuf = *st; + stream->statbuf.st_size -= + (off_t)mstream->header_size.physical_size - + (off_t)mstream->header_size.virtual_size; return &stream->statbuf; }
--- a/src/lib-storage/index/mbox/istream-raw-mbox.c Thu Jun 08 21:52:40 2006 +0300 +++ b/src/lib-storage/index/mbox/istream-raw-mbox.c Thu Jun 08 22:26:53 2006 +0300 @@ -309,8 +309,15 @@ static const struct stat *_stat(struct _istream *stream, bool exact) { struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream; + const struct stat *st; - return i_stream_stat(rstream->input, exact); + st = i_stream_stat(rstream->input, exact); + if (st == NULL) + return NULL; + + stream->statbuf = *st; + stream->statbuf.st_size = -1; + return &stream->statbuf; } struct istream *i_stream_create_raw_mbox(pool_t pool, struct istream *input)