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 5b60c45c7 feat(services/obs): Rewrite methods signature in obs using 
OpRead/OpStat (#3094)
5b60c45c7 is described below

commit 5b60c45c74017a53ffd6ced0e68be834cf05190e
Author: hanhotfox <[email protected]>
AuthorDate: Sun Sep 17 10:16:54 2023 +0800

    feat(services/obs): Rewrite methods signature in obs using OpRead/OpStat 
(#3094)
    
    feat(services/obs): rewrite methods signature in obs using OpRead/OpStat
---
 core/src/services/obs/backend.rs | 22 ++++------------------
 core/src/services/obs/core.rs    | 35 +++++++++++------------------------
 core/src/services/obs/writer.rs  |  5 ++++-
 3 files changed, 19 insertions(+), 43 deletions(-)

diff --git a/core/src/services/obs/backend.rs b/core/src/services/obs/backend.rs
index 1db5cc0a8..3d6281e86 100644
--- a/core/src/services/obs/backend.rs
+++ b/core/src/services/obs/backend.rs
@@ -306,16 +306,8 @@ impl Accessor for ObsBackend {
 
     async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
         let mut req = match args.operation() {
-            PresignOperation::Stat(v) => {
-                self.core
-                    .obs_head_object_request(path, v.if_match(), 
v.if_none_match())?
-            }
-            PresignOperation::Read(v) => self.core.obs_get_object_request(
-                path,
-                v.range(),
-                v.if_match(),
-                v.if_none_match(),
-            )?,
+            PresignOperation::Stat(v) => 
self.core.obs_head_object_request(path, v)?,
+            PresignOperation::Read(v) => 
self.core.obs_get_object_request(path, v)?,
             PresignOperation::Write(v) => {
                 self.core
                     .obs_put_object_request(path, None, v, AsyncBody::Empty)?
@@ -357,10 +349,7 @@ impl Accessor for ObsBackend {
     }
 
     async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
-        let resp = self
-            .core
-            .obs_get_object(path, args.range(), args.if_match(), 
args.if_none_match())
-            .await?;
+        let resp = self.core.obs_get_object(path, &args).await?;
 
         let status = resp.status();
 
@@ -405,10 +394,7 @@ impl Accessor for ObsBackend {
             return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
         }
 
-        let resp = self
-            .core
-            .obs_head_object(path, args.if_match(), args.if_none_match())
-            .await?;
+        let resp = self.core.obs_head_object(path, &args).await?;
 
         let status = resp.status();
 
diff --git a/core/src/services/obs/core.rs b/core/src/services/obs/core.rs
index 965f99427..de9d2a735 100644
--- a/core/src/services/obs/core.rs
+++ b/core/src/services/obs/core.rs
@@ -104,39 +104,32 @@ impl ObsCore {
     pub async fn obs_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.obs_get_object_request(path, range, if_match, 
if_none_match)?;
+        let mut req = self.obs_get_object_request(path, args)?;
 
         self.sign(&mut req).await?;
 
         self.send(req).await
     }
 
-    pub fn obs_get_object_request(
-        &self,
-        path: &str,
-        range: BytesRange,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
-    ) -> Result<Request<AsyncBody>> {
+    pub fn obs_get_object_request(&self, path: &str, args: &OpRead) -> 
Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
         let url = format!("{}/{}", self.endpoint, percent_encode_path(&p));
 
         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);
         }
 
+        let range = args.range();
         if !range.is_full() {
             req = req.header(http::header::RANGE, range.to_header())
         }
 
-        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);
         }
 
@@ -179,22 +172,16 @@ impl ObsCore {
     pub async fn obs_head_object(
         &self,
         path: &str,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
+        args: &OpStat,
     ) -> Result<Response<IncomingAsyncBody>> {
-        let mut req = self.obs_head_object_request(path, if_match, 
if_none_match)?;
+        let mut req = self.obs_head_object_request(path, args)?;
 
         self.sign(&mut req).await?;
 
         self.send(req).await
     }
 
-    pub fn obs_head_object_request(
-        &self,
-        path: &str,
-        if_match: Option<&str>,
-        if_none_match: Option<&str>,
-    ) -> Result<Request<AsyncBody>> {
+    pub fn obs_head_object_request(&self, path: &str, args: &OpStat) -> 
Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
         let url = format!("{}/{}", self.endpoint, percent_encode_path(&p));
@@ -204,11 +191,11 @@ impl ObsCore {
 
         let mut req = Request::head(&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);
         }
 
diff --git a/core/src/services/obs/writer.rs b/core/src/services/obs/writer.rs
index 3e0741c98..82daefee5 100644
--- a/core/src/services/obs/writer.rs
+++ b/core/src/services/obs/writer.rs
@@ -172,7 +172,10 @@ impl oio::MultipartUploadWrite for ObsWriter {
 #[async_trait]
 impl oio::AppendObjectWrite for ObsWriter {
     async fn offset(&self) -> Result<u64> {
-        let resp = self.core.obs_head_object(&self.path, None, None).await?;
+        let resp = self
+            .core
+            .obs_head_object(&self.path, &OpStat::default())
+            .await?;
 
         let status = resp.status();
         match status {

Reply via email to