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 2325bb80b feat(services/cos): Rewrite the methods signature using
OpStat/OpRead (#3073)
2325bb80b is described below
commit 2325bb80b61f91721cf157ce0cf9a3f498e67450
Author: Au <[email protected]>
AuthorDate: Fri Sep 15 14:41:39 2023 +0800
feat(services/cos): Rewrite the methods signature using OpStat/OpRead
(#3073)
* feat(services/cos)!: Rewrite the methods signature using OpStat/OpRead
* chore(services/cos): format code to make it happy
---
core/src/services/cos/backend.rs | 22 ++++------------------
core/src/services/cos/core.rs | 35 +++++++++++------------------------
core/src/services/cos/writer.rs | 5 ++++-
3 files changed, 19 insertions(+), 43 deletions(-)
diff --git a/core/src/services/cos/backend.rs b/core/src/services/cos/backend.rs
index b41f12b5e..e01da22cb 100644
--- a/core/src/services/cos/backend.rs
+++ b/core/src/services/cos/backend.rs
@@ -322,10 +322,7 @@ impl Accessor for CosBackend {
}
async fn read(&self, path: &str, args: OpRead) -> Result<(RpRead,
Self::Reader)> {
- let resp = self
- .core
- .cos_get_object(path, args.range(), args.if_match(),
args.if_none_match())
- .await?;
+ let resp = self.core.cos_get_object(path, &args).await?;
let status = resp.status();
@@ -370,10 +367,7 @@ impl Accessor for CosBackend {
return Ok(RpStat::new(Metadata::new(EntryMode::DIR)));
}
- let resp = self
- .core
- .cos_head_object(path, args.if_match(), args.if_none_match())
- .await?;
+ let resp = self.core.cos_head_object(path, &args).await?;
let status = resp.status();
@@ -402,16 +396,8 @@ impl Accessor for CosBackend {
async fn presign(&self, path: &str, args: OpPresign) -> Result<RpPresign> {
let mut req = match args.operation() {
- PresignOperation::Stat(v) => {
- self.core
- .cos_head_object_request(path, v.if_match(),
v.if_none_match())?
- }
- PresignOperation::Read(v) => self.core.cos_get_object_request(
- path,
- v.range(),
- v.if_match(),
- v.if_none_match(),
- )?,
+ PresignOperation::Stat(v) =>
self.core.cos_head_object_request(path, v)?,
+ PresignOperation::Read(v) =>
self.core.cos_get_object_request(path, v)?,
PresignOperation::Write(v) => {
self.core
.cos_put_object_request(path, None, v, AsyncBody::Empty)?
diff --git a/core/src/services/cos/core.rs b/core/src/services/cos/core.rs
index 27e428b23..d9c085c40 100644
--- a/core/src/services/cos/core.rs
+++ b/core/src/services/cos/core.rs
@@ -104,39 +104,32 @@ impl CosCore {
pub async fn cos_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.cos_get_object_request(path, range, if_match,
if_none_match)?;
+ let mut req = self.cos_get_object_request(path, args)?;
self.sign(&mut req).await?;
self.send(req).await
}
- pub fn cos_get_object_request(
- &self,
- path: &str,
- range: BytesRange,
- if_match: Option<&str>,
- if_none_match: Option<&str>,
- ) -> Result<Request<AsyncBody>> {
+ pub fn cos_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);
}
@@ -181,33 +174,27 @@ impl CosCore {
pub async fn cos_head_object(
&self,
path: &str,
- if_match: Option<&str>,
- if_none_match: Option<&str>,
+ args: &OpStat,
) -> Result<Response<IncomingAsyncBody>> {
- let mut req = self.cos_head_object_request(path, if_match,
if_none_match)?;
+ let mut req = self.cos_head_object_request(path, args)?;
self.sign(&mut req).await?;
self.send(req).await
}
- pub fn cos_head_object_request(
- &self,
- path: &str,
- if_match: Option<&str>,
- if_none_match: Option<&str>,
- ) -> Result<Request<AsyncBody>> {
+ pub fn cos_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));
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/cos/writer.rs b/core/src/services/cos/writer.rs
index 26c833de6..0363a6471 100644
--- a/core/src/services/cos/writer.rs
+++ b/core/src/services/cos/writer.rs
@@ -175,7 +175,10 @@ impl oio::MultipartUploadWrite for CosWriter {
#[async_trait]
impl oio::AppendObjectWrite for CosWriter {
async fn offset(&self) -> Result<u64> {
- let resp = self.core.cos_head_object(&self.path, None, None).await?;
+ let resp = self
+ .core
+ .cos_head_object(&self.path, &OpStat::default())
+ .await?;
let status = resp.status();
match status {