From: Markus Valentin Date: Fri, 25 Jun 2021 12:52:11 +0000 (+0200) Subject: lib-fs: metawrap - Fix handling empty file X-Git-Tag: 2.3.16~24 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ab3757e44ef5101a4440d919992285b72c1cfc1b;p=thirdparty%2Fdovecot%2Fcore.git lib-fs: metawrap - Fix handling empty file As empty files are already closed when fs-metawrap attempts to append metadata there have been problems with size calculation. Fix this by relying on the same mechanism as if metadata changed during write. This recreates metadata and keeps old body. This fixes an issue when writing empty mails to cache (failed: Cached message size larger than expected). This was introduced by 03e102ddccaae9e944c503d4269de755731798e8a --- diff --git a/src/lib-fs/fs-metawrap.c b/src/lib-fs/fs-metawrap.c index f6c86f3668..22517e741e 100644 --- a/src/lib-fs/fs-metawrap.c +++ b/src/lib-fs/fs-metawrap.c @@ -396,15 +396,11 @@ static int fs_metawrap_write_stream_finish(struct fs_file *_file, bool success) /* finish writing the temporary file */ if (file->temp_output->offset == 0) { /* empty file - temp_output is already finished, - so we can't write to it. */ - string_t *str = t_str_new(128); - - o_stream_destroy(&file->temp_output); - fs_metawrap_append_metadata(file, str); - input = i_stream_create_copy_from_data(str_data(str), str_len(str)); - } else { - input = iostream_temp_finish(&file->temp_output, IO_BLOCK_SIZE); + so we can't write to it. To make sure metadata is still + appended/written to file use metadata_changed_since_write */ + file->metadata_changed_since_write = TRUE; } + input = iostream_temp_finish(&file->temp_output, IO_BLOCK_SIZE); if (file->metadata_changed_since_write) { /* we'll need to recreate the metadata. do this by creating a new istream combining the new metadata header and the