Skip to content

Commit

Permalink
Add source uri to headers for COPY request
Browse files Browse the repository at this point in the history
  • Loading branch information
Ilya Isaev committed Jan 13, 2025
1 parent 3da84c5 commit a1f50ad
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
31 changes: 26 additions & 5 deletions mountpoint-s3-client/src/s3_crt_client/copy_object.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
use std::ops::Deref;

Check warning on line 1 in mountpoint-s3-client/src/s3_crt_client/copy_object.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/mountpoint-s3/mountpoint-s3/mountpoint-s3-client/src/s3_crt_client/copy_object.rs
use std::os::unix::prelude::OsStrExt;

use tracing::trace;
use mountpoint_s3_crt::{http::request_response::Header, s3::client::MetaRequestResult};

use crate::endpoint_config::EndpointError;
use crate::object_client::{CopyObjectError, CopyObjectParams, CopyObjectResult, ObjectClientResult};
use crate::s3_crt_client::{S3CrtClient, S3Operation, S3RequestError};
use crate::s3_crt_client::{ConstructionError, S3CrtClient, S3CrtClientInner, S3Operation, S3RequestError};

Check warning on line 8 in mountpoint-s3-client/src/s3_crt_client/copy_object.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/mountpoint-s3/mountpoint-s3/mountpoint-s3-client/src/s3_crt_client/copy_object.rs
impl From<EndpointError> for S3RequestError {
fn from(error: EndpointError) -> Self {
S3RequestError::ConstructionFailure(ConstructionError::InvalidEndpoint(error))
}
}

impl S3CrtClient {
/// Create and begin a new CopyObject request.
Expand Down Expand Up @@ -40,8 +46,23 @@ impl S3CrtClient {
destination_key
);

Check warning on line 47 in mountpoint-s3-client/src/s3_crt_client/copy_object.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/mountpoint-s3/mountpoint-s3/mountpoint-s3-client/src/s3_crt_client/copy_object.rs

self.inner
.make_simple_http_request(message, S3Operation::CopyObject, span, parse_copy_object_error)?
let mut options = S3CrtClientInner::new_meta_request_options(message, S3Operation::CopyObject);
let endpoint = self.inner.endpoint_config.resolve_for_bucket(source_bucket)
.map_err(|e| S3RequestError::from(e))?;
let uri = endpoint.uri()
.map_err(|e| S3RequestError::from(e))?;
let hostname = uri.host_name().to_str().unwrap();
let path_prefix = uri.path().to_os_string().into_string().unwrap();
let port = uri.host_port();
let hostname_header = if port > 0 {
format!("{}:{}", hostname, port)
} else {
hostname.to_string()
};
let source_uri = format!("{hostname_header}{path_prefix}/{source_key}");

Check warning on line 62 in mountpoint-s3-client/src/s3_crt_client/copy_object.rs

View workflow job for this annotation

GitHub Actions / Formatting

Diff in /home/runner/work/mountpoint-s3/mountpoint-s3/mountpoint-s3-client/src/s3_crt_client/copy_object.rs
trace!(source_uri, "resolved source uri");
options.copy_source_uri(&source_uri);
self.inner.make_simple_http_request_from_options(options, span, |_| {}, parse_copy_object_error, |_, _| ())?
};

let _body = request.await?;
Expand Down
8 changes: 8 additions & 0 deletions mountpoint-s3-crt/src/s3/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -462,6 +462,14 @@ impl<'a> MetaRequestOptions<'a> {
options.inner.send_using_async_writes = send_using_async_writes;
self
}

/// Set the URI of source bucket/key for COPY request only
pub fn copy_source_uri(&mut self, source_uri: &str) -> &mut Self {
// SAFETY: we aren't moving out of the struct.
let options = unsafe { Pin::get_unchecked_mut(Pin::as_mut(&mut self.0)) };
options.inner.copy_source_uri = unsafe { source_uri.as_aws_byte_cursor() };

Check failure on line 470 in mountpoint-s3-crt/src/s3/client.rs

View workflow job for this annotation

GitHub Actions / Tests (FUSE 3)

no field `copy_source_uri` on type `mountpoint_s3_crt_sys::aws_s3_meta_request_options`

Check failure on line 470 in mountpoint-s3-crt/src/s3/client.rs

View workflow job for this annotation

GitHub Actions / Cargo benchmarks

no field `copy_source_uri` on type `mountpoint_s3_crt_sys::aws_s3_meta_request_options`

Check failure on line 470 in mountpoint-s3-crt/src/s3/client.rs

View workflow job for this annotation

GitHub Actions / Check all targets

no field `copy_source_uri` on type `mountpoint_s3_crt_sys::aws_s3_meta_request_options`

Check failure on line 470 in mountpoint-s3-crt/src/s3/client.rs

View workflow job for this annotation

GitHub Actions / Clippy

no field `copy_source_uri` on type `mountpoint_s3_crt_sys::aws_s3_meta_request_options`

Check failure on line 470 in mountpoint-s3-crt/src/s3/client.rs

View workflow job for this annotation

GitHub Actions / rustdoc tests

no field `copy_source_uri` on type `mountpoint_s3_crt_sys::aws_s3_meta_request_options`

Check failure on line 470 in mountpoint-s3-crt/src/s3/client.rs

View workflow job for this annotation

GitHub Actions / Tests (MacOS)

no field `copy_source_uri` on type `mountpoint_s3_crt_sys::aws_s3_meta_request_options`

Check failure on line 470 in mountpoint-s3-crt/src/s3/client.rs

View workflow job for this annotation

GitHub Actions / Shuttle tests

no field `copy_source_uri` on type `mountpoint_s3_crt_sys::aws_s3_meta_request_options`
self
}
}

impl Default for MetaRequestOptions<'_> {
Expand Down

0 comments on commit a1f50ad

Please sign in to comment.