if (file->copy_input != NULL) {
i_stream_unref(&file->copy_input);
- (void)fs_write_stream_abort(file, &file->copy_output);
+ fs_write_stream_abort(file, &file->copy_output);
}
i_free_and_null(file->write_digest);
if (file->fs->v.file_close != NULL) T_BEGIN {
output = fs_write_stream(file);
if ((ret = o_stream_send(output, data, size)) < 0) {
err = errno;
- fs_set_error(file->fs, "fs_write(%s) failed: %s",
- o_stream_get_name(output),
- o_stream_get_error(output));
- fs_write_stream_abort(file, &output);
+ fs_write_stream_abort_error(file, &output, "fs_write(%s) failed: %s",
+ o_stream_get_name(output),
+ o_stream_get_error(output));
errno = err;
return -1;
}
return fs_write_stream_finish_int(file, TRUE);
}
-void fs_write_stream_abort(struct fs_file *file, struct ostream **output)
+void fs_write_stream_abort_error(struct fs_file *file, struct ostream **output, const char *error_fmt, ...)
{
int ret;
+ va_list args;
+ va_start(args, error_fmt);
i_assert(*output == file->output);
i_assert(file->output != NULL);
*output = NULL;
o_stream_ignore_last_errors(file->output);
/* make sure we don't have an old error lying around */
- fs_set_error(file->fs, "Write aborted");
+ fs_set_verror(file->fs, error_fmt, args);
ret = fs_write_stream_finish_int(file, FALSE);
i_assert(ret != 0);
+
+ va_end(args);
+}
+
+void fs_write_stream_abort(struct fs_file *file, struct ostream **output)
+{
+ fs_write_stream_abort_error(file, output, "Write aborted");
}
void fs_write_set_hash(struct fs_file *file, const struct hash_method *method,
return -1;
case OSTREAM_SEND_ISTREAM_RESULT_ERROR_INPUT:
errno = dest->copy_input->stream_errno;
- fs_set_error(dest->fs, "read(%s) failed: %s",
- i_stream_get_name(dest->copy_input),
- i_stream_get_error(dest->copy_input));
+ fs_write_stream_abort_error(dest, &dest->copy_output,
+ "read(%s) failed: %s",
+ i_stream_get_name(dest->copy_input),
+ i_stream_get_error(dest->copy_input));
i_stream_unref(&dest->copy_input);
- fs_write_stream_abort(dest, &dest->copy_output);
return -1;
case OSTREAM_SEND_ISTREAM_RESULT_ERROR_OUTPUT:
errno = dest->copy_output->stream_errno;
- fs_set_error(dest->fs, "write(%s) failed: %s",
- o_stream_get_name(dest->copy_output),
- o_stream_get_error(dest->copy_output));
+ fs_write_stream_abort_error(dest, &dest->copy_output,
+ "write(%s) failed: %s",
+ o_stream_get_name(dest->copy_output),
+ o_stream_get_error(dest->copy_output));
i_stream_unref(&dest->copy_input);
- fs_write_stream_abort(dest, &dest->copy_output);
return -1;
}
i_stream_unref(&dest->copy_input);