From: Timo Sirainen Date: Tue, 5 Jun 2018 11:22:08 +0000 (+0300) Subject: lib-compression: deflate ostream - Use Z_FINISH on final flush X-Git-Tag: 2.3.9~1737 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3b9fd6391ca2ab34c324013b6567451c489e427a;p=thirdparty%2Fdovecot%2Fcore.git lib-compression: deflate ostream - Use Z_FINISH on final flush 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. --- diff --git a/src/lib-compression/ostream-zlib.c b/src/lib-compression/ostream-zlib.c index c34937c9bb..67584d4667 100644 --- a/src/lib-compression/ostream-zlib.c +++ b/src/lib-compression/ostream-zlib.c @@ -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; } diff --git a/src/lib-compression/test-compression.c b/src/lib-compression/test-compression.c index 11141c0cca..2996e49e92 100644 --- a/src/lib-compression/test-compression.c +++ b/src/lib-compression/test-compression.c @@ -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);