Skip to content

Commit

Permalink
global: Use o_stream_nsend_istream() where useful
Browse files Browse the repository at this point in the history
We can skip all of the io error handling and just leave it to
o_stream_nfinish().
  • Loading branch information
sirainen authored and GitLab committed May 18, 2016
1 parent b90fb7f commit 6f187ae
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 66 deletions.
8 changes: 1 addition & 7 deletions src/doveadm/client-connection-http.c
Expand Up @@ -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);
Expand Down
12 changes: 1 addition & 11 deletions src/doveadm/doveadm-fs.c
Expand Up @@ -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) {
Expand Down Expand Up @@ -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",
Expand Down
19 changes: 2 additions & 17 deletions src/lib-fs/fs-metawrap.c
Expand Up @@ -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;
}
Expand Down
4 changes: 1 addition & 3 deletions src/lib-lda/mail-send.c
Expand Up @@ -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);
Expand Down
9 changes: 2 additions & 7 deletions src/lib-storage/index/dbox-multi/mdbox-purge.c
Expand Up @@ -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,
Expand Down
6 changes: 1 addition & 5 deletions src/lib-storage/index/dbox-single/sdbox-file.c
Expand Up @@ -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);

Expand Down
18 changes: 2 additions & 16 deletions src/plugins/fs-compress/fs-compress.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6f187ae

Please sign in to comment.