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 32d139969 feat(services/azblob): Rewrite azblob methods signature 
using OpRead/OpStat (#3072)
32d139969 is described below

commit 32d13996925f36c639b5efa63316c62f4874a497
Author: Au <[email protected]>
AuthorDate: Sat Sep 16 11:51:26 2023 +0800

    feat(services/azblob): Rewrite azblob methods signature using OpRead/OpStat 
(#3072)
    
    * feat(services/azblob)!: rewrite azblob methods signature using 
OpRead/OpStat
    
    * chore(services/azblob): remove redundant code
    
    * feat(services/azblob): use OpStat instead of OpRead in 
azblob_get_blob_properties
---
 core/src/services/azblob/backend.rs | 29 ++++----------------------
 core/src/services/azblob/core.rs    | 41 +++++++++++--------------------------
 core/src/services/azblob/writer.rs  |  2 +-
 3 files changed, 17 insertions(+), 55 deletions(-)

diff --git a/core/src/services/azblob/backend.rs 
b/core/src/services/azblob/backend.rs
index 967cdd712..627d6fb02 100644
--- a/core/src/services/azblob/backend.rs
+++ b/core/src/services/azblob/backend.rs
@@ -580,16 +580,7 @@ impl Accessor for AzblobBackend {
     }
 
     async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead, 
Self::Reader)> {
-        let resp = self
-            .core
-            .azblob_get_blob(
-                path,
-                args.range(),
-                args.if_none_match(),
-                args.if_match(),
-                args.override_content_disposition(),
-            )
-            .await?;
+        let resp = self.core.azblob_get_blob(path, &args).await?;
 
         let status = resp.status();
 
@@ -634,10 +625,7 @@ impl Accessor for AzblobBackend {
             return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
         }
 
-        let resp = self
-            .core
-            .azblob_get_blob_properties(path, args.if_none_match(), 
args.if_match())
-            .await?;
+        let resp = self.core.azblob_get_blob_properties(path, &args).await?;
 
         let status = resp.status();
 
@@ -674,17 +662,8 @@ impl Accessor for AzblobBackend {
 
     async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
         let mut req = match args.operation() {
-            PresignOperation::Stat(v) => {
-                self.core
-                    .azblob_head_blob_request(path, v.if_none_match(), 
v.if_match())?
-            }
-            PresignOperation::Read(v) => self.core.azblob_get_blob_request(
-                path,
-                v.range(),
-                v.if_none_match(),
-                v.if_match(),
-                v.override_content_disposition(),
-            )?,
+            PresignOperation::Stat(v) => 
self.core.azblob_head_blob_request(path, v)?,
+            PresignOperation::Read(v) => 
self.core.azblob_get_blob_request(path, v)?,
             PresignOperation::Write(_) => self.core.azblob_put_blob_request(
                 path,
                 None,
diff --git a/core/src/services/azblob/core.rs b/core/src/services/azblob/core.rs
index e493ff1ab..7db055660 100644
--- a/core/src/services/azblob/core.rs
+++ b/core/src/services/azblob/core.rs
@@ -157,14 +157,7 @@ impl AzblobCore {
 }
 
 impl AzblobCore {
-    pub fn azblob_get_blob_request(
-        &self,
-        path: &str,
-        range: BytesRange,
-        if_none_match: Option<&str>,
-        if_match: Option<&str>,
-        override_content_disposition: Option<&str>,
-    ) -> Result<Request<AsyncBody>> {
+    pub fn azblob_get_blob_request(&self, path: &str, args: &OpRead) -> 
Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
         let mut url = format!(
@@ -175,7 +168,7 @@ impl AzblobCore {
         );
 
         let mut query_args = Vec::new();
-        if let Some(override_content_disposition) = 
override_content_disposition {
+        if let Some(override_content_disposition) = 
args.override_content_disposition() {
             query_args.push(format!(
                 "rscd={}",
                 percent_encode_path(override_content_disposition)
@@ -191,6 +184,7 @@ impl AzblobCore {
         // Set SSE headers.
         req = self.insert_sse_headers(req);
 
+        let range = args.range();
         if !range.is_full() {
             // azblob doesn't support read with suffix range.
             //
@@ -205,11 +199,11 @@ impl AzblobCore {
             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);
         }
 
-        if let Some(if_match) = if_match {
+        if let Some(if_match) = args.if_match() {
             req = req.header(IF_MATCH, if_match);
         }
 
@@ -223,18 +217,9 @@ impl AzblobCore {
     pub async fn azblob_get_blob(
         &self,
         path: &str,
-        range: BytesRange,
-        if_none_match: Option<&str>,
-        if_match: Option<&str>,
-        override_content_disposition: Option<&str>,
+        args: &OpRead,
     ) -> Result<Response<IncomingAsyncBody>> {
-        let mut req = self.azblob_get_blob_request(
-            path,
-            range,
-            if_none_match,
-            if_match,
-            override_content_disposition,
-        )?;
+        let mut req = self.azblob_get_blob_request(path, args)?;
 
         self.sign(&mut req).await?;
 
@@ -387,8 +372,7 @@ impl AzblobCore {
     pub fn azblob_head_blob_request(
         &self,
         path: &str,
-        if_none_match: Option<&str>,
-        if_match: Option<&str>,
+        args: &OpStat,
     ) -> Result<Request<AsyncBody>> {
         let p = build_abs_path(&self.root, path);
 
@@ -404,11 +388,11 @@ impl AzblobCore {
         // Set SSE headers.
         req = self.insert_sse_headers(req);
 
-        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);
         }
 
@@ -422,10 +406,9 @@ impl AzblobCore {
     pub async fn azblob_get_blob_properties(
         &self,
         path: &str,
-        if_none_match: Option<&str>,
-        if_match: Option<&str>,
+        args: &OpStat,
     ) -> Result<Response<IncomingAsyncBody>> {
-        let mut req = self.azblob_head_blob_request(path, if_none_match, 
if_match)?;
+        let mut req = self.azblob_head_blob_request(path, args)?;
 
         self.sign(&mut req).await?;
         self.send(req).await
diff --git a/core/src/services/azblob/writer.rs 
b/core/src/services/azblob/writer.rs
index bfcde2007..d78ae8dc7 100644
--- a/core/src/services/azblob/writer.rs
+++ b/core/src/services/azblob/writer.rs
@@ -75,7 +75,7 @@ impl oio::AppendObjectWrite for AzblobWriter {
     async fn offset(&self) -> Result<u64> {
         let resp = self
             .core
-            .azblob_get_blob_properties(&self.path, None, None)
+            .azblob_get_blob_properties(&self.path, &OpStat::default())
             .await?;
 
         let status = resp.status();

Reply via email to