Skip to content

Commit

Permalink
lib-fs: fs-metawrap - Don't try to write to an already finished ostream
Browse files Browse the repository at this point in the history
Fixes a crash after recent changes when trying to write an empty file via
fs-metawrap.
  • Loading branch information
sirainen authored and Timo Sirainen committed Nov 1, 2017
1 parent 8a4a0ef commit 03e102d
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/lib-fs/fs-metawrap.c
Expand Up @@ -391,10 +391,16 @@ 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 */
fs_metawrap_write_metadata_to(file, file->temp_output);
/* 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);
}
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
Expand Down

0 comments on commit 03e102d

Please sign in to comment.