From: Timo Sirainen Date: Mon, 16 May 2016 17:06:30 +0000 (+0300) Subject: global: Use o_stream_nsend_istream() where useful X-Git-Tag: 2.3.0.rc1~3717 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6f187ae85911f63cb87271246c68f3c13a0adb7b;p=thirdparty%2Fdovecot%2Fcore.git global: Use o_stream_nsend_istream() where useful We can skip all of the io error handling and just leave it to o_stream_nfinish(). --- diff --git a/src/doveadm/client-connection-http.c b/src/doveadm/client-connection-http.c index 30c6d19610..750f8ef420 100644 --- a/src/doveadm/client-connection-http.c +++ b/src/doveadm/client-connection-http.c @@ -189,13 +189,7 @@ static void doveadm_http_server_json_success(void *context, struct istream *resu string_t *escaped; escaped = str_new(conn->client.pool, 10); o_stream_nsend_str(conn->client.output,"[\"doveadmResponse\","); - if (o_stream_send_istream(conn->client.output, result) < 0) { - if (conn->client.output->stream_errno != 0) { - i_fatal("write(%s) failed: %s", o_stream_get_name(conn->client.output), o_stream_get_error(conn->client.output)); - } else if (result->stream_errno != 0) { - i_fatal("read(%s) failed: %s", i_stream_get_name(result), i_stream_get_error(result)); - } else i_unreached(); /* either it's output or input error */ - } + o_stream_nsend_istream(conn->client.output, result); o_stream_nsend_str(conn->client.output,",\""); if (conn->method_id != NULL) { json_append_escaped(escaped, conn->method_id); diff --git a/src/doveadm/doveadm-fs.c b/src/doveadm/doveadm-fs.c index 51f9f99fa8..b0e066d8b7 100644 --- a/src/doveadm/doveadm-fs.c +++ b/src/doveadm/doveadm-fs.c @@ -99,7 +99,6 @@ static void cmd_fs_put(int argc, char *argv[]) struct istream *input; struct ostream *output; buffer_t *hash = NULL; - off_t ret; int c; while ((c = getopt(argc, argv, "h:")) > 0) { @@ -137,16 +136,7 @@ static void cmd_fs_put(int argc, char *argv[]) output = fs_write_stream(file); input = i_stream_create_file(src_path, IO_BLOCK_SIZE); - if ((ret = o_stream_send_istream(output, input)) < 0) { - if (output->stream_errno != 0) { - i_error("write(%s) failed: %s", dest_path, - o_stream_get_error(output)); - } else { - i_error("read(%s) failed: %s", src_path, - i_stream_get_error(input)); - } - doveadm_exit_code = EX_TEMPFAIL; - } + o_stream_nsend_istream(output, input); i_stream_destroy(&input); if (fs_write_stream_finish(file, &output) < 0) { i_error("fs_write_stream_finish() failed: %s", diff --git a/src/lib-fs/fs-metawrap.c b/src/lib-fs/fs-metawrap.c index ceb2b84b41..e162b164f9 100644 --- a/src/lib-fs/fs-metawrap.c +++ b/src/lib-fs/fs-metawrap.c @@ -430,23 +430,8 @@ 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); - (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 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); - } + o_stream_nsend_istream(file->super_output, input); + ret = fs_write_stream_finish(file->super, &file->super_output); i_stream_unref(&input); return ret; } diff --git a/src/lib-lda/mail-send.c b/src/lib-lda/mail-send.c index d277dbf4f5..359d9e9c2b 100644 --- a/src/lib-lda/mail-send.c +++ b/src/lib-lda/mail-send.c @@ -170,10 +170,8 @@ int mail_send_rejection(struct mail_deliver_context *ctx, const char *recipient, N_ELEMENTS(exclude_headers), *null_header_filter_callback, (void *)NULL); - ret = o_stream_send_istream(output, input); + o_stream_nsend_istream(output, input); i_stream_unref(&input); - - i_assert(ret != 0); } str_truncate(str, 0); diff --git a/src/lib-storage/index/dbox-multi/mdbox-purge.c b/src/lib-storage/index/dbox-multi/mdbox-purge.c index ffafdc562e..a22292e465 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-purge.c +++ b/src/lib-storage/index/dbox-multi/mdbox-purge.c @@ -206,13 +206,8 @@ mdbox_purge_save_msg(struct mdbox_purge_context *ctx, struct dbox_file *file, i_assert(file != out_file_append->file); input = i_stream_create_limit(file->input, msg_size); - (void)o_stream_send_istream(output, input); - if (input->stream_errno != 0) { - mail_storage_set_critical(&file->storage->storage, - "read(%s) failed: %s", file->cur_path, - i_stream_get_error(input)); - ret = -1; - } else if (o_stream_nfinish(output) < 0) { + o_stream_nsend_istream(output, input); + if (o_stream_nfinish(output) < 0) { mail_storage_set_critical(&file->storage->storage, "write(%s) failed: %s", out_file_append->file->cur_path, diff --git a/src/lib-storage/index/dbox-single/sdbox-file.c b/src/lib-storage/index/dbox-single/sdbox-file.c index 47622b9fed..56e5b98cdf 100644 --- a/src/lib-storage/index/dbox-single/sdbox-file.c +++ b/src/lib-storage/index/dbox-single/sdbox-file.c @@ -323,15 +323,11 @@ int sdbox_file_move(struct dbox_file *file, bool alt_path) output = o_stream_create_fd_file(out_fd, 0, FALSE); i_stream_seek(file->input, 0); - ret = o_stream_send_istream(output, file->input) > 0 ? 0 : -1; + o_stream_nsend_istream(output, file->input); if (o_stream_nfinish(output) < 0) { mail_storage_set_critical(storage, "write(%s) failed: %s", temp_path, o_stream_get_error(output)); ret = -1; - } else if (file->input->stream_errno != 0) { - mail_storage_set_critical(storage, "read(%s) failed: %s", - temp_path, i_stream_get_error(file->input)); - ret = -1; } o_stream_unref(&output); diff --git a/src/plugins/fs-compress/fs-compress.c b/src/plugins/fs-compress/fs-compress.c index 4088c58db7..66e61b8038 100644 --- a/src/plugins/fs-compress/fs-compress.c +++ b/src/plugins/fs-compress/fs-compress.c @@ -274,22 +274,8 @@ static int fs_compress_write_stream_finish(struct fs_file *_file, bool success) /* finish writing the temporary file */ input = iostream_temp_finish(&file->temp_output, IO_BLOCK_SIZE); 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) { - 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); - 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; - } + o_stream_nsend_istream(file->super_output, input); + ret = fs_write_stream_finish(file->super, &file->super_output); i_stream_unref(&input); return ret; }