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 42b12e392 refactor(services/gcs): Rewrite `gcs` methods signature by 
using OpXxxx (#3087)
42b12e392 is described below

commit 42b12e3926df26d4266e91d085d827c5dd56cf8c
Author: taobo <[email protected]>
AuthorDate: Fri Sep 15 16:23:00 2023 +0800

    refactor(services/gcs): Rewrite `gcs` methods signature by using OpXxxx 
(#3087)
    
    the gcs part of issue: #3064
---
 core/src/services/gcs/backend.rs | 26 ++++-------------
 core/src/services/gcs/core.rs    | 61 +++++++++++++++-------------------------
 2 files changed, 28 insertions(+), 59 deletions(-)

diff --git a/core/src/services/gcs/backend.rs b/core/src/services/gcs/backend.rs
index d8ad7b9ce..57ce7cfbd 100644
--- a/core/src/services/gcs/backend.rs
+++ b/core/src/services/gcs/backend.rs
@@ -385,10 +385,7 @@ impl Accessor for GcsBackend {
     }
 
     async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
-        let resp = self
-            .core
-            .gcs_get_object(path, args.range(), args.if_match(), 
args.if_none_match())
-            .await?;
+        let resp = self.core.gcs_get_object(path, &args).await?;
 
         if resp.status().is_success() {
             let meta = parse_into_metadata(path, resp.headers())?;
@@ -422,10 +419,7 @@ impl Accessor for GcsBackend {
             return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
         }
 
-        let resp = self
-            .core
-            .gcs_get_object_metadata(path, args.if_match(), 
args.if_none_match())
-            .await?;
+        let resp = self.core.gcs_get_object_metadata(path, &args).await?;
 
         if resp.status().is_success() {
             // read http response body
@@ -549,19 +543,11 @@ impl Accessor for GcsBackend {
     async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
         // We will not send this request out, just for signing.
         let mut req = match args.operation() {
-            PresignOperation::Stat(v) => {
+            PresignOperation::Stat(v) => 
self.core.gcs_head_object_xml_request(path, v)?,
+            PresignOperation::Read(v) => 
self.core.gcs_get_object_xml_request(path, v)?,
+            PresignOperation::Write(v) => {
                 self.core
-                    .gcs_head_object_xml_request(path, v.if_match(), 
v.if_none_match())?
-            }
-            PresignOperation::Read(v) => self.core.gcs_get_object_xml_request(
-                path,
-                v.range(),
-                v.if_match(),
-                v.if_none_match(),
-            )?,
-            PresignOperation::Write(_) => {
-                self.core
-                    .gcs_insert_object_xml_request(path, None, 
AsyncBody::Empty)?
+                    .gcs_insert_object_xml_request(path, v, AsyncBody::Empty)?
             }
         };
 
diff --git a/core/src/services/gcs/core.rs b/core/src/services/gcs/core.rs
index c9eeb9cb8..5720db2cb 100644
--- a/core/src/services/gcs/core.rs
+++ b/core/src/services/gcs/core.rs
@@ -146,13 +146,7 @@ impl GcsCore {
 }
 
 impl GcsCore {
-    pub fn gcs_get_object_request(
-        &self,
-        path: &str,
-        range: BytesRange,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
-    ) -> Result<Request<AsyncBody>> {
+    pub fn gcs_get_object_request(&self, path: &str, args: &OpRead) -> 
Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
         let url = format!(
@@ -164,14 +158,14 @@ impl GcsCore {
 
         let mut req = Request::get(&url);
 
-        if let Some(if_match) = if_match {
+        if let Some(if_match) = args.if_match() {
             req = req.header(IF_MATCH, if_match);
         }
-        if let Some(if_none_match) = if_none_match {
+        if let Some(if_none_match) = args.if_none_match() {
             req = req.header(IF_NONE_MATCH, if_none_match);
         }
-        if !range.is_full() {
-            req = req.header(http::header::RANGE, range.to_header());
+        if !args.range().is_full() {
+            req = req.header(http::header::RANGE, args.range().to_header());
         }
 
         let req = req
@@ -185,9 +179,7 @@ impl GcsCore {
     pub fn gcs_get_object_xml_request(
         &self,
         path: &str,
-        range: BytesRange,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
+        args: &OpRead,
     ) -> Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
@@ -195,14 +187,14 @@ impl GcsCore {
 
         let mut req = Request::get(&url);
 
-        if let Some(if_match) = if_match {
+        if let Some(if_match) = args.if_match() {
             req = req.header(IF_MATCH, if_match);
         }
-        if let Some(if_none_match) = if_none_match {
+        if let Some(if_none_match) = args.if_none_match() {
             req = req.header(IF_NONE_MATCH, if_none_match);
         }
-        if !range.is_full() {
-            req = req.header(http::header::RANGE, range.to_header());
+        if !args.range().is_full() {
+            req = req.header(http::header::RANGE, args.range().to_header());
         }
 
         let req = req
@@ -215,11 +207,9 @@ impl GcsCore {
     pub async fn gcs_get_object(
         &self,
         path: &str,
-        range: BytesRange,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
+        args: &OpRead,
     ) -> Result<Response<IncomingAsyncBody>> {
-        let mut req = self.gcs_get_object_request(path, range, if_match, 
if_none_match)?;
+        let mut req = self.gcs_get_object_request(path, args)?;
 
         self.sign(&mut req).await?;
         self.send(req).await
@@ -316,7 +306,7 @@ impl GcsCore {
     pub fn gcs_insert_object_xml_request(
         &self,
         path: &str,
-        content_type: Option<&str>,
+        args: &OpWrite,
         body: AsyncBody,
     ) -> Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
@@ -325,7 +315,7 @@ impl GcsCore {
 
         let mut req = Request::put(&url);
 
-        if let Some(content_type) = content_type {
+        if let Some(content_type) = args.content_type() {
             req = req.header(CONTENT_TYPE, content_type);
         }
 
@@ -342,12 +332,7 @@ impl GcsCore {
         Ok(req)
     }
 
-    pub fn gcs_head_object_request(
-        &self,
-        path: &str,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
-    ) -> Result<Request<AsyncBody>> {
+    pub fn gcs_head_object_request(&self, path: &str, args: &OpStat) -> 
Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
         let url = format!(
@@ -359,11 +344,11 @@ impl GcsCore {
 
         let mut req = Request::get(&url);
 
-        if let Some(if_none_match) = if_none_match {
+        if let Some(if_none_match) = args.if_none_match() {
             req = req.header(IF_NONE_MATCH, if_none_match);
         }
 
-        if let Some(if_match) = if_match {
+        if let Some(if_match) = args.if_match() {
             req = req.header(IF_MATCH, if_match);
         }
 
@@ -378,8 +363,7 @@ impl GcsCore {
     pub fn gcs_head_object_xml_request(
         &self,
         path: &str,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
+        args: &OpStat,
     ) -> Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
@@ -387,11 +371,11 @@ impl GcsCore {
 
         let mut req = Request::head(&url);
 
-        if let Some(if_none_match) = if_none_match {
+        if let Some(if_none_match) = args.if_none_match() {
             req = req.header(IF_NONE_MATCH, if_none_match);
         }
 
-        if let Some(if_match) = if_match {
+        if let Some(if_match) = args.if_match() {
             req = req.header(IF_MATCH, if_match);
         }
 
@@ -405,10 +389,9 @@ impl GcsCore {
     pub async fn gcs_get_object_metadata(
         &self,
         path: &str,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
+        args: &OpStat,
     ) -> Result<Response<IncomingAsyncBody>> {
-        let mut req = self.gcs_head_object_request(path, if_match, 
if_none_match)?;
+        let mut req = self.gcs_head_object_request(path, args)?;
 
         self.sign(&mut req).await?;
 

Reply via email to