]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-compression: deflate ostream - Use Z_FINISH on final flush
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 5 Jun 2018 11:22:08 +0000 (14:22 +0300)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Tue, 5 Jun 2018 12:16:20 +0000 (15:16 +0300)
Nowadays we have o_stream_finish(), so we can differentiate between
intermediate flush and final flush. Using this allows istream-zlib to
cleanly see that the stream ends.

src/lib-compression/ostream-zlib.c
src/lib-compression/test-compression.c

index c34937c9bbe5f486607509a6828f7454b6845096..67584d46679e9f81e3e8abe9acd745bcd39d11f6 100644 (file)
@@ -161,8 +161,7 @@ o_stream_zlib_send_chunk(struct zlib_ostream *zstream,
 
        zstream->crc = crc32_data_more(zstream->crc, data, size);
        zstream->bytes32 += size;
-       zstream->flushed = flush == Z_SYNC_FLUSH && zs->avail_in == 0 &&
-               zs->avail_out == sizeof(zstream->outbuf);
+       zstream->flushed = FALSE;
        return size;
 }
 
@@ -189,8 +188,8 @@ o_stream_zlib_send_flush(struct zlib_ostream *zstream, bool final)
        if ((ret = o_stream_zlib_send_outbuf(zstream)) <= 0)
                return ret;
 
-       flush = !zstream->gz ? Z_SYNC_FLUSH :
-               (final ? Z_FINISH : Z_NO_FLUSH);
+       flush = final ? Z_FINISH :
+               (!zstream->gz ? Z_SYNC_FLUSH : Z_NO_FLUSH);
 
        i_assert(zstream->outbuf_used == 0);
        do {
@@ -222,7 +221,7 @@ o_stream_zlib_send_flush(struct zlib_ostream *zstream, bool final)
                if (o_stream_zlib_send_gz_trailer(zstream) < 0)
                        return -1;
        }
-       if (final || flush != Z_NO_FLUSH)
+       if (final)
                zstream->flushed = TRUE;
        return 0;
 }
index 11141c0cca37e0161fc1060b6e5f426e9a70124a..2996e49e925b31b3066d543a07202fd43e983e05 100644 (file)
@@ -76,6 +76,7 @@ static void test_compression_handler(const struct compression_handler *handler)
                i_stream_skip(input, size);
        }
        test_assert(ret == -1);
+       test_assert(input->stream_errno == 0);
        i_stream_destroy(&input);
        i_stream_destroy(&file_input);
        sha1_result(&sha1, input_sha1);