]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib: Fixed istream_seekable.stat() to return correct size.
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 13 May 2016 17:35:50 +0000 (13:35 -0400)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Fri, 13 May 2016 17:36:59 +0000 (13:36 -0400)
It was supposed to read until end of the stream, but it did it only when
stat() was called while stream was still fully in memory.

src/lib/istream-seekable.c

index a12581813c9721719fb28fcf8d0f45052305a539..f6340be5f9510c754b40cb08cb086d490880ec13 100644 (file)
@@ -316,25 +316,24 @@ i_stream_seekable_stat(struct istream_private *stream, bool exact)
                return 0;
        }
 
-       if (sstream->membuf != NULL) {
-               /* we want to know the full size of the file, so read until
-                  we're finished */
-               old_offset = stream->istream.v_offset;
-               do {
-                       i_stream_skip(&stream->istream,
-                                     stream->pos - stream->skip);
-               } while ((ret = i_stream_seekable_read(stream)) > 0);
-
-               if (ret == 0) {
-                       i_panic("i_stream_stat() used for non-blocking "
-                               "seekable stream %s offset %"PRIuUOFF_T,
-                               i_stream_get_name(sstream->cur_input),
-                               sstream->cur_input->v_offset);
-               }
-               i_stream_skip(&stream->istream, stream->pos - stream->skip);
-               i_stream_seek(&stream->istream, old_offset);
-               unref_streams(sstream);
+       /* we want to know the full size of the file, so read until
+          we're finished */
+       old_offset = stream->istream.v_offset;
+       do {
+               i_stream_skip(&stream->istream,
+                             stream->pos - stream->skip);
+       } while ((ret = i_stream_seekable_read(stream)) > 0);
+
+       if (ret == 0) {
+               i_panic("i_stream_stat() used for non-blocking "
+                       "seekable stream %s offset %"PRIuUOFF_T,
+                       i_stream_get_name(sstream->cur_input),
+                       sstream->cur_input->v_offset);
        }
+       i_stream_skip(&stream->istream, stream->pos - stream->skip);
+       i_stream_seek(&stream->istream, old_offset);
+       unref_streams(sstream);
+
        if (stream->istream.stream_errno != 0)
                return -1;