This is an automated email from the ASF dual-hosted git repository.

xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git


The following commit(s) were added to refs/heads/main by this push:
     new 8b4a395c9  feat(services/s3): Rewrite the method signatures using 
OpWrite (#3078)
8b4a395c9 is described below

commit 8b4a395c9d0b3926eef89d4a0719d12d689e253e
Author: sunheyi <[email protected]>
AuthorDate: Fri Sep 15 13:00:46 2023 +0800

     feat(services/s3): Rewrite the method signatures using OpWrite (#3078)
    
    * Rewrite the method signatures using OpWrite
    
    * fix method error
    
    * reformat code
---
 core/src/services/s3/backend.rs | 19 ++++++++++++-------
 core/src/services/s3/core.rs    | 22 +++++++++-------------
 core/src/services/s3/writer.rs  | 18 ++++--------------
 3 files changed, 25 insertions(+), 34 deletions(-)

diff --git a/core/src/services/s3/backend.rs b/core/src/services/s3/backend.rs
index e0433a831..85ef4ca2f 100644
--- a/core/src/services/s3/backend.rs
+++ b/core/src/services/s3/backend.rs
@@ -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?;
 
@@ -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?;
diff --git a/core/src/services/s3/core.rs b/core/src/services/s3/core.rs
index f775fb99a..3c809246c 100644
--- a/core/src/services/s3/core.rs
+++ b/core/src/services/s3/core.rs
@@ -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);
@@ -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)
         }
 
@@ -517,9 +515,7 @@ 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,
     ) -> Result<Response<IncomingAsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
@@ -527,15 +523,15 @@ impl S3Core {
 
         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)
         }
 
diff --git a/core/src/services/s3/writer.rs b/core/src/services/s3/writer.rs
index 76c874ed0..fa8505c37 100644
--- a/core/src/services/s3/writer.rs
+++ b/core/src/services/s3/writer.rs
@@ -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?;
 
@@ -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();

Reply via email to