Skip to content

Commit

Permalink
seems to work
Browse files Browse the repository at this point in the history
  • Loading branch information
waahm7 committed Jan 9, 2025
1 parent 4fb6aa8 commit 70a3500
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 14 deletions.
3 changes: 3 additions & 0 deletions include/aws/s3/private/s3_copy_object.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "aws/s3/private/s3_meta_request_impl.h"
#include <aws/common/uri.h>

enum aws_s3_copy_object_request_tag {
AWS_S3_COPY_OBJECT_REQUEST_TAG_GET_OBJECT_SIZE,
Expand All @@ -25,6 +26,8 @@ struct aws_s3_copy_object {
/* Usable after the Create Multipart Upload request succeeds. */
struct aws_string *upload_id;

struct aws_uri source_uri;

/* Only meant for use in the update function, which is never called concurrently. */
struct {
uint32_t next_part_number;
Expand Down
3 changes: 2 additions & 1 deletion include/aws/s3/private/s3_request_messages.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,8 @@ struct aws_http_message *aws_s3_get_object_size_message_new(
AWS_S3_API
struct aws_http_message *aws_s3_get_source_object_size_message_new(
struct aws_allocator *allocator,
struct aws_http_message *base_message);
struct aws_http_message *base_message,
struct aws_uri *source_uri);

/* Add content-md5 header to the http message passed in. The MD5 will be computed from the input_buf */
AWS_S3_API
Expand Down
3 changes: 3 additions & 0 deletions include/aws/s3/s3_client.h
Original file line number Diff line number Diff line change
Expand Up @@ -869,6 +869,9 @@ struct aws_s3_meta_request_options {
* This is just used as an estimate, so it's okay to provide an approximate value if the exact size is unknown.
*/
const uint64_t *object_size_hint;


const struct aws_byte_cursor copy_source_uri;
};

/* Result details of a meta request.
Expand Down
16 changes: 13 additions & 3 deletions source/s3_copy_object.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ struct aws_s3_meta_request *aws_s3_meta_request_copy_object_new(
copy_object,
&s_s3_copy_object_vtable,
&copy_object->base)) {
aws_mem_release(allocator, copy_object);
return NULL;
goto on_error;
}

aws_array_list_init_dynamic(
Expand All @@ -92,10 +91,20 @@ struct aws_s3_meta_request *aws_s3_meta_request_copy_object_new(
copy_object->synced_data.content_length = UNKNOWN_CONTENT_LENGTH;
copy_object->synced_data.total_num_parts = UNKNOWN_NUM_PARTS;
copy_object->threaded_update_data.next_part_number = 1;
if(options->copy_source_uri.len != 0) {
if(aws_uri_init_parse(&copy_object->source_uri, allocator, &options->copy_source_uri)) {
// TODO: log
goto on_error;
}

}

AWS_LOGF_DEBUG(AWS_LS_S3_META_REQUEST, "id=%p Created new CopyObject Meta Request.", (void *)&copy_object->base);

return &copy_object->base;
on_error:
aws_mem_release(allocator, copy_object);
return NULL;
}

static void s_s3_meta_request_copy_object_destroy(struct aws_s3_meta_request *meta_request) {
Expand All @@ -105,6 +114,7 @@ static void s_s3_meta_request_copy_object_destroy(struct aws_s3_meta_request *me
struct aws_s3_copy_object *copy_object = meta_request->impl;

aws_string_destroy(copy_object->upload_id);
aws_uri_clean_up(&copy_object->source_uri);
copy_object->upload_id = NULL;

for (size_t part_index = 0; part_index < aws_array_list_length(&copy_object->synced_data.part_list); ++part_index) {
Expand Down Expand Up @@ -364,7 +374,7 @@ static struct aws_future_void *s_s3_copy_object_prepare_request(struct aws_s3_re
/* Prepares the GetObject HEAD request to get the source object size. */
case AWS_S3_COPY_OBJECT_REQUEST_TAG_GET_OBJECT_SIZE: {
message = aws_s3_get_source_object_size_message_new(
meta_request->allocator, meta_request->initial_request_message);
meta_request->allocator, meta_request->initial_request_message, &copy_object->source_uri);
break;
}

Expand Down
39 changes: 29 additions & 10 deletions source/s3_request_messages.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <aws/common/byte_buf.h>
#include <aws/common/encoding.h>
#include <aws/common/string.h>
#include <aws/common/uri.h>
#include <aws/http/request_response.h>
#include <aws/io/async_stream.h>
#include <aws/io/stream.h>
Expand Down Expand Up @@ -457,8 +458,35 @@ static const struct aws_byte_cursor s_slash_char = AWS_BYTE_CUR_INIT_FROM_STRING
*/
struct aws_http_message *aws_s3_get_source_object_size_message_new(
struct aws_allocator *allocator,
struct aws_http_message *base_message) {
struct aws_http_message *base_message,
struct aws_uri *source_uri) {
struct aws_http_message *message = NULL;

message = aws_http_message_new_request(allocator);
if (message == NULL) {
goto error_cleanup;
}

if (aws_http_message_set_request_method(message, g_head_method)) {
goto error_cleanup;
}
if (source_uri->self_size > 0) {
struct aws_byte_cursor host = *aws_uri_host_name(source_uri);
struct aws_byte_cursor path = *aws_uri_path(source_uri);
struct aws_http_header host_header = {
.name = g_host_header_name,
.value = host,
};
if (aws_http_message_add_header(message, host_header)) {
goto error_cleanup;
}

if (aws_http_message_set_request_path(message, path)) {
goto error_cleanup;
}
return message;
}

struct aws_byte_buf head_object_host_header;
AWS_ZERO_STRUCT(head_object_host_header);

Expand Down Expand Up @@ -529,15 +557,6 @@ struct aws_http_message *aws_s3_get_source_object_size_message_new(
goto error_cleanup;
}

message = aws_http_message_new_request(allocator);
if (message == NULL) {
goto error_cleanup;
}

if (aws_http_message_set_request_method(message, g_head_method)) {
goto error_cleanup;
}

struct aws_http_header host_header = {
.name = g_host_header_name,
.value = aws_byte_cursor_from_buf(&head_object_host_header),
Expand Down

0 comments on commit 70a3500

Please sign in to comment.