Skip to content

Commit b19fbd4

Browse files
authored
use the recv filepath directly from C (#591)
1 parent 0565b6e commit b19fbd4

File tree

1 file changed

+1
-53
lines changed

1 file changed

+1
-53
lines changed

source/s3_meta_request.c

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,6 @@ struct s3_meta_request_binding {
2424
/* Reference to python object that reference to other related python object to keep it alive */
2525
PyObject *py_core;
2626

27-
/**
28-
* file path if set, it handles file operation from C land to reduce the cost
29-
* passing chunks from C into python. One for recv/writing, the other for send/reading
30-
**/
31-
FILE *recv_file;
32-
3327
/* Batch up the transferred size in one sec. */
3428
uint64_t size_transferred;
3529
/* The time stamp when the progress reported */
@@ -42,9 +36,6 @@ struct aws_s3_meta_request *aws_py_get_s3_meta_request(PyObject *meta_request) {
4236
}
4337

4438
static void s_destroy(struct s3_meta_request_binding *meta_request) {
45-
if (meta_request->recv_file) {
46-
fclose(meta_request->recv_file);
47-
}
4839
Py_XDECREF(meta_request->py_core);
4940
aws_mem_release(aws_py_get_allocator(), meta_request);
5041
}
@@ -148,22 +139,6 @@ static int s_s3_request_on_body(
148139
void *user_data) {
149140
(void)meta_request;
150141
struct s3_meta_request_binding *request_binding = user_data;
151-
152-
if (request_binding->recv_file) {
153-
/* The callback will be invoked with the right order, so we don't need to seek first. */
154-
if (fwrite((void *)body->ptr, body->len, 1, request_binding->recv_file) < 1) {
155-
int errno_value = ferror(request_binding->recv_file) ? errno : 0; /* Always cache errno */
156-
aws_translate_and_raise_io_error_or(errno_value, AWS_ERROR_FILE_WRITE_FAILURE);
157-
AWS_LOGF_ERROR(
158-
AWS_LS_S3_META_REQUEST,
159-
"id=%p Failed writing to file. errno:%d. aws-error:%s",
160-
(void *)meta_request,
161-
errno_value,
162-
aws_error_name(aws_last_error()));
163-
return AWS_OP_ERR;
164-
}
165-
return AWS_OP_SUCCESS;
166-
}
167142
bool error = true;
168143
/*************** GIL ACQUIRE ***************/
169144
PyGILState_STATE state;
@@ -201,25 +176,6 @@ static void s_s3_request_on_finish(
201176
struct s3_meta_request_binding *request_binding = user_data;
202177

203178
int error_code = meta_request_result->error_code;
204-
205-
if (request_binding->recv_file) {
206-
if (fclose(request_binding->recv_file) != 0) {
207-
/* Failed to close file, so we can't guarantee it flushed to disk.
208-
* If the meta-request's error_code was 0, change it to failure */
209-
if (error_code == 0) {
210-
int errno_value = errno; /* Always cache errno before potential side-effect */
211-
aws_translate_and_raise_io_error_or(errno_value, AWS_ERROR_FILE_WRITE_FAILURE);
212-
error_code = aws_last_error();
213-
AWS_LOGF_ERROR(
214-
AWS_LS_S3_META_REQUEST,
215-
"id=%p Failed closing file. errno:%d. aws-error:%s",
216-
(void *)meta_request,
217-
errno_value,
218-
aws_error_name(error_code));
219-
}
220-
}
221-
request_binding->recv_file = NULL;
222-
}
223179
/*************** GIL ACQUIRE ***************/
224180
PyGILState_STATE state;
225181
if (aws_py_gilstate_ensure(&state)) {
@@ -455,22 +411,14 @@ PyObject *aws_py_s3_client_make_meta_request(PyObject *self, PyObject *args) {
455411
meta_request->py_core = py_core;
456412
Py_INCREF(meta_request->py_core);
457413

458-
if (recv_filepath) {
459-
meta_request->recv_file = aws_fopen(recv_filepath, "wb");
460-
if (!meta_request->recv_file) {
461-
aws_translate_and_raise_io_error(errno);
462-
PyErr_SetAwsLastError();
463-
goto error;
464-
}
465-
}
466-
467414
struct aws_s3_meta_request_options s3_meta_request_opt = {
468415
.type = type,
469416
.operation_name = aws_byte_cursor_from_c_str(operation_name),
470417
.message = http_request,
471418
.signing_config = signing_config,
472419
.checksum_config = &checksum_config,
473420
.send_filepath = aws_byte_cursor_from_c_str(send_filepath),
421+
.recv_filepath = aws_byte_cursor_from_c_str(recv_filepath),
474422
.headers_callback = s_s3_request_on_headers,
475423
.body_callback = s_s3_request_on_body,
476424
.finish_callback = s_s3_request_on_finish,

0 commit comments

Comments
 (0)