]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-fs: metawrap - Fix handling empty file
authorMarkus Valentin <markus.valentin@open-xchange.com>
Fri, 25 Jun 2021 12:52:11 +0000 (14:52 +0200)
committerMarkus Valentin <markus.valentin@open-xchange.com>
Tue, 29 Jun 2021 12:55:51 +0000 (14:55 +0200)
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

src/lib-fs/fs-metawrap.c

index f6c86f366832895ce9ae89f79ec1a751e63c4b46..22517e741e32a635ad853000b0ee69842adb0515 100644 (file)
@@ -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