Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(services/s3): Rewrite the method signatures using OpWrite #3078

Merged
merged 4 commits into from
Sep 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions core/src/services/s3/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -945,9 +945,12 @@ impl Accessor for S3Backend {
}

async fn create_dir(&self, path: &str, _: OpCreateDir) -> Result<RpCreateDir> {
let mut req =
self.core
.s3_put_object_request(path, Some(0), None, None, None, AsyncBody::Empty)?;
let mut req = self.core.s3_put_object_request(
path,
Some(0),
&OpWrite::default(),
AsyncBody::Empty,
)?;

self.core.sign(&mut req).await?;

Expand Down Expand Up @@ -1061,10 +1064,12 @@ impl Accessor for S3Backend {
.s3_head_object_request(path, v.if_none_match(), v.if_match())?
}
PresignOperation::Read(v) => self.core.s3_get_object_request(path, v.clone())?,
PresignOperation::Write(_) => {
self.core
.s3_put_object_request(path, None, None, None, None, AsyncBody::Empty)?
}
PresignOperation::Write(_) => self.core.s3_put_object_request(
path,
None,
&OpWrite::default(),
AsyncBody::Empty,
)?,
};

self.core.sign_query(&mut req, args.expire()).await?;
Expand Down
22 changes: 9 additions & 13 deletions core/src/services/s3/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,9 +336,7 @@ impl S3Core {
&self,
path: &str,
size: Option<u64>,
content_type: Option<&str>,
content_disposition: Option<&str>,
cache_control: Option<&str>,
args: &OpWrite,
body: AsyncBody,
) -> Result<Request<AsyncBody>> {
let p = build_abs_path(&self.root, path);
Expand All @@ -348,18 +346,18 @@ impl S3Core {
let mut req = Request::put(&url);

if let Some(size) = size {
req = req.header(CONTENT_LENGTH, size)
req = req.header(CONTENT_LENGTH, size.to_string())
}

if let Some(mime) = content_type {
if let Some(mime) = args.content_type() {
req = req.header(CONTENT_TYPE, mime)
}

if let Some(pos) = content_disposition {
if let Some(pos) = args.content_disposition() {
req = req.header(CONTENT_DISPOSITION, pos)
}

if let Some(cache_control) = cache_control {
if let Some(cache_control) = args.cache_control() {
req = req.header(CACHE_CONTROL, cache_control)
}

Expand Down Expand Up @@ -517,25 +515,23 @@ impl S3Core {
pub async fn s3_initiate_multipart_upload(
&self,
path: &str,
content_type: Option<&str>,
content_disposition: Option<&str>,
cache_control: Option<&str>,
args: &OpWrite,
Xuanwo marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<Response<IncomingAsyncBody>> {
let p = build_abs_path(&self.root, path);

let url = format!("{}/{}?uploads", self.endpoint, percent_encode_path(&p));

let mut req = Request::post(&url);

if let Some(mime) = content_type {
if let Some(mime) = args.content_type() {
req = req.header(CONTENT_TYPE, mime)
}

if let Some(content_disposition) = content_disposition {
if let Some(content_disposition) = args.content_disposition() {
req = req.header(CONTENT_DISPOSITION, content_disposition)
}

if let Some(cache_control) = cache_control {
if let Some(cache_control) = args.cache_control() {
req = req.header(CACHE_CONTROL, cache_control)
}

Expand Down
18 changes: 4 additions & 14 deletions core/src/services/s3/writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,9 @@ impl S3Writer {
#[async_trait]
impl oio::MultipartUploadWrite for S3Writer {
async fn write_once(&self, size: u64, body: AsyncBody) -> Result<()> {
let mut req = self.core.s3_put_object_request(
&self.path,
Some(size),
self.op.content_type(),
self.op.content_disposition(),
self.op.cache_control(),
body,
)?;
let mut req = self
.core
.s3_put_object_request(&self.path, Some(size), &self.op, body)?;

self.core.sign(&mut req).await?;

Expand All @@ -74,12 +69,7 @@ impl oio::MultipartUploadWrite for S3Writer {
async fn initiate_part(&self) -> Result<String> {
let resp = self
.core
.s3_initiate_multipart_upload(
&self.path,
self.op.content_type(),
self.op.content_disposition(),
self.op.cache_control(),
)
.s3_initiate_multipart_upload(&self.path, &self.op)
.await?;

let status = resp.status();
Expand Down