Skip to content

Commit

Permalink
lib-fs: Make sure fs-metawrap catches all write errors.
Browse files Browse the repository at this point in the history
The full istream may not have been written in case ostream only partially
wrote the data (e.g. out of disk space?)
  • Loading branch information
sirainen committed May 13, 2016
1 parent da653f2 commit ed47ce7
Showing 1 changed file with 6 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/lib-fs/fs-metawrap.c
Expand Up @@ -430,21 +430,22 @@ static int fs_metawrap_write_stream_finish(struct fs_file *_file, bool success)
i_stream_unref(&input2);
}
file->super_output = fs_write_stream(file->super);
if (o_stream_send_istream(file->super_output, input) >= 0)
ret = fs_write_stream_finish(file->super, &file->super_output);
else if (input->stream_errno != 0) {
(void)o_stream_send_istream(file->super_output, input);
if (input->stream_errno != 0) {
fs_set_error(_file->fs, "read(%s) failed: %s",
i_stream_get_name(input),
i_stream_get_error(input));
fs_write_stream_abort(file->super, &file->super_output);
ret = -1;
} else {
i_assert(file->super_output->stream_errno != 0);
} else if (file->super_output->stream_errno != 0) {
fs_set_error(_file->fs, "write(%s) failed: %s",
o_stream_get_name(file->super_output),
o_stream_get_error(file->super_output));
fs_write_stream_abort(file->super, &file->super_output);
ret = -1;
} else {
i_assert(i_stream_is_eof(input));
ret = fs_write_stream_finish(file->super, &file->super_output);
}
i_stream_unref(&input);
return ret;
Expand Down

0 comments on commit ed47ce7

Please sign in to comment.