From: Timo Sirainen Date: Fri, 13 May 2016 13:56:08 +0000 (-0400) Subject: lib-fs: Make sure fs-metawrap catches all write errors. X-Git-Tag: 2.3.0.rc1~3766 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ed47ce764bfdd40b70919f2c917d237b0a2e4aed;p=thirdparty%2Fdovecot%2Fcore.git lib-fs: Make sure fs-metawrap catches all write errors. The full istream may not have been written in case ostream only partially wrote the data (e.g. out of disk space?) --- diff --git a/src/lib-fs/fs-metawrap.c b/src/lib-fs/fs-metawrap.c index 6a4fd759c7..ceb2b84b41 100644 --- a/src/lib-fs/fs-metawrap.c +++ b/src/lib-fs/fs-metawrap.c @@ -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;