]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
global: Use o_stream_nsend_istream() where useful
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 16 May 2016 17:06:30 +0000 (20:06 +0300)
committerGitLab <gitlab@git.dovecot.net>
Wed, 18 May 2016 12:21:30 +0000 (15:21 +0300)
We can skip all of the io error handling and just leave it to
o_stream_nfinish().

src/doveadm/client-connection-http.c
src/doveadm/doveadm-fs.c
src/lib-fs/fs-metawrap.c
src/lib-lda/mail-send.c
src/lib-storage/index/dbox-multi/mdbox-purge.c
src/lib-storage/index/dbox-single/sdbox-file.c
src/plugins/fs-compress/fs-compress.c

index 30c6d19610e45fdcb0d91f9ad1ed2f55289560b2..750f8ef420b5d715b60526dd3b9b791871df4e3a 100644 (file)
@@ -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);
index 51f9f99fa8e6884aaf22e69a0d2181c641761a6f..b0e066d8b7dc4d6a8f97e6043cde9c494353eecd 100644 (file)
@@ -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",
index ceb2b84b41d2dbe2a503da335969ea340e4850f4..e162b164f9ad170b070a81cfa9e368b877e4f2d4 100644 (file)
@@ -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;
 }
index d277dbf4f5a673c2f5a2a6019e5422fe75936957..359d9e9c2bc768aaa03bcb1d8f3f0acf65125fd2 100644 (file)
@@ -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);
index ffafdc562e25f7b427751022112606a73280d022..a22292e465ea1b428315d1d8b53e0573a9bc2774 100644 (file)
@@ -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,
index 47622b9fed34a9d593407b15d1522139e84c81de..56e5b98cdfe2a81baa52f68a48336fa052611fda 100644 (file)
@@ -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);
 
index 4088c58db7fd2ae4a684cb2a24a43d092407fd1b..66e61b80387c4a5541988bab600753bf20cdc421 100644 (file)
@@ -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;
 }