Skip to content

Commit a12d2cb

Browse files
committed
fix the logic for empty file
2 parents 772c4a0 + e4ba8f1 commit a12d2cb

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

include/aws/s3/s3_client.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,11 @@ enum aws_s3_recv_file_options {
315315
AWS_S3_RECV_FILE_WRITE_TO_POSITION,
316316
};
317317

318-
/* Controls how client performance file I/O operations. Only applies to the file based workload. */
318+
/**
319+
* WARNING: experimental/unstable:
320+
* Controls how client performance file I/O operations. Only applies to the file based
321+
* workload.
322+
**/
319323
struct aws_s3_file_io_options {
320324
/**
321325
* Skip buffering the part in memory before sending the request.

source/s3_auto_ranged_get.c

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct aws_s3_meta_request *aws_s3_meta_request_auto_ranged_get_new(
112112
}
113113
}
114114
auto_ranged_get->initial_message_has_if_match_header = aws_http_headers_has(headers, g_if_match_header_name);
115+
115116
auto_ranged_get->synced_data.first_part_size = auto_ranged_get->base.part_size;
116117
if (options->object_size_hint != NULL) {
117118
auto_ranged_get->object_size_hint_available = true;
@@ -764,22 +765,28 @@ static void s_s3_auto_ranged_get_request_finished(
764765
goto update_synced_data;
765766
}
766767
/* Always extract ETag header for part size estimation */
767-
struct aws_byte_cursor etag_header_value;
768-
if (aws_http_headers_get(request->send_data.response_headers, g_etag_header_name, &etag_header_value) ==
769-
AWS_OP_SUCCESS) {
770-
AWS_LOGF_TRACE(
771-
AWS_LS_S3_META_REQUEST,
772-
"id=%p ETag received for the meta request. value is: " PRInSTR "",
773-
(void *)meta_request,
774-
AWS_BYTE_CURSOR_PRI(etag_header_value));
768+
if (!request_failed || first_part_size_mismatch) {
769+
struct aws_byte_cursor etag_header_value;
770+
AWS_ASSERT(auto_ranged_get->etag == NULL);
771+
if (aws_http_headers_get(request->send_data.response_headers, g_etag_header_name, &etag_header_value) ==
772+
AWS_OP_SUCCESS) {
773+
AWS_LOGF_TRACE(
774+
AWS_LS_S3_META_REQUEST,
775+
"id=%p ETag received for the meta request. value is: " PRInSTR "",
776+
(void *)meta_request,
777+
AWS_BYTE_CURSOR_PRI(etag_header_value));
775778

776-
/* Store ETag if needed for If-Match header */
777-
if ((!request_failed || first_part_size_mismatch) &&
778-
!auto_ranged_get->initial_message_has_if_match_header) {
779-
AWS_ASSERT(auto_ranged_get->etag == NULL);
780-
auto_ranged_get->etag = aws_string_new_from_cursor(auto_ranged_get->base.allocator, &etag_header_value);
779+
if (!auto_ranged_get->initial_message_has_if_match_header) {
780+
/* Store ETag if needed for If-Match header */
781+
auto_ranged_get->etag =
782+
aws_string_new_from_cursor(auto_ranged_get->base.allocator, &etag_header_value);
783+
}
784+
} else {
785+
AWS_LOGF_ERROR(AWS_LS_S3_META_REQUEST, "id=%p ETag headers are missing", (void *)meta_request);
786+
aws_raise_error(AWS_ERROR_S3_MISSING_ETAG);
787+
error_code = AWS_ERROR_S3_MISSING_ETAG;
788+
goto update_synced_data;
781789
}
782-
783790
/* Extract number of parts from ETag and calculate estimated part size */
784791
uint32_t num_parts = 0;
785792
if (aws_s3_extract_parts_from_etag(etag_header_value, &num_parts) == AWS_OP_SUCCESS && num_parts > 0) {
@@ -794,16 +801,11 @@ static void s_s3_auto_ranged_get_request_finished(
794801
num_parts,
795802
auto_ranged_get->estimated_object_stored_part_size);
796803
} else {
797-
/* failed to parse ETag header, error out */
804+
/* Failed to parse ETags */
798805
aws_raise_error(AWS_ERROR_S3_MISSING_ETAG);
799806
error_code = AWS_ERROR_S3_MISSING_ETAG;
800807
goto update_synced_data;
801808
}
802-
} else {
803-
/* No ETag header found, error out */
804-
aws_raise_error(AWS_ERROR_S3_MISSING_ETAG);
805-
error_code = AWS_ERROR_S3_MISSING_ETAG;
806-
goto update_synced_data;
807809
}
808810

809811
/* If we were able to discover the object-range/content length successfully, then any error code that was passed

0 commit comments

Comments
 (0)