Skip to content

Commit

Permalink
feat(services/oss): Add Copy Support (#1874)
Browse files Browse the repository at this point in the history
* feat(oss): support copy

Signed-off-by: suyanhanx <suyanhanx@gmail.com>

* try fix

Signed-off-by: suyanhanx <suyanhanx@gmail.com>

---------

Signed-off-by: suyanhanx <suyanhanx@gmail.com>
  • Loading branch information
suyanhanx committed Apr 8, 2023
1 parent e0db2ed commit 3e42fef
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion core/src/services/oss/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ use crate::*;
///
/// - [x] read
/// - [x] write
/// - [x] copy
/// - [x] list
/// - [x] scan
/// - [ ] presign
Expand Down Expand Up @@ -417,7 +418,7 @@ impl Accessor for OssBackend {
.set_root(&self.root)
.set_name(&self.bucket)
.set_max_batch_operations(1000)
.set_capabilities(Read | Write | List | Scan | Presign | Batch)
.set_capabilities(Read | Write | Copy | List | Scan | Presign | Batch)
.set_hints(ReadStreamable);

am
Expand Down Expand Up @@ -475,6 +476,19 @@ impl Accessor for OssBackend {
))
}

async fn copy(&self, from: &str, to: &str, _args: OpCopy) -> Result<RpCopy> {
let resp = self.oss_copy_object(from, to).await?;
let status = resp.status();

match status {
StatusCode::OK => {
resp.into_body().consume().await?;
Ok(RpCopy::default())
}
_ => Err(parse_error(resp).await?),
}
}

async fn stat(&self, path: &str, _: OpStat) -> Result<RpStat> {
if path == "/" {
let m = Metadata::new(EntryMode::DIR);
Expand Down Expand Up @@ -756,6 +770,26 @@ impl OssBackend {
self.client.send_async(req).await
}

async fn oss_copy_object(&self, from: &str, to: &str) -> Result<Response<IncomingAsyncBody>> {
let source = build_abs_path(&self.root, from);
let target = build_abs_path(&self.root, to);

let url = format!(
"{}/{}",
self.get_endpoint(false),
percent_encode_path(&target)
);
let source = format!("/{}/{}", self.bucket, percent_encode_path(&source));

let mut req = Request::put(&url)
.header("x-oss-copy-source", source)
.body(AsyncBody::Empty)
.map_err(new_request_build_error)?;

self.signer.sign(&mut req).map_err(new_request_sign_error)?;
self.client.send_async(req).await
}

pub(super) async fn oss_list_object(
&self,
path: &str,
Expand Down

0 comments on commit 3e42fef

Please sign in to comment.