From 74ec9d51b7e79759bc8a3303ce0bd17719bfa7f3 Mon Sep 17 00:00:00 2001 From: liugddx Date: Mon, 9 Sep 2024 23:07:02 +0800 Subject: [PATCH] 1 --- core/src/services/lakefs/backend.rs | 19 ++++++++++++++++++- core/src/services/lakefs/core.rs | 23 +++++++++++++++++++++++ core/src/services/lakefs/docs.md | 2 +- 3 files changed, 42 insertions(+), 2 deletions(-) diff --git a/core/src/services/lakefs/backend.rs b/core/src/services/lakefs/backend.rs index 69e59e395ff..d3fb208cbbc 100644 --- a/core/src/services/lakefs/backend.rs +++ b/core/src/services/lakefs/backend.rs @@ -208,7 +208,7 @@ impl Access for LakefsBackend { list: true, read: true, write: true, - + delete: true, ..Default::default() }); am.into() @@ -285,4 +285,21 @@ impl Access for LakefsBackend { oio::OneShotWriter::new(LakefsWriter::new(self.core.clone(), path.to_string(), args)), )) } + + async fn delete(&self, path: &str, args: OpDelete) -> Result { + // This would delete the bucket, do not perform + if self.core.root == "/" && path == "/" { + return Ok(RpDelete::default()); + } + + let resp = self.core.delete_object(path, &args).await?; + + let status = resp.status(); + + match status { + StatusCode::NO_CONTENT => Ok(RpDelete::default()), + StatusCode::NOT_FOUND => Ok(RpDelete::default()), + _ => Err(parse_error(resp).await?), + } + } } diff --git a/core/src/services/lakefs/core.rs b/core/src/services/lakefs/core.rs index 91aed0e3493..62aa065f70b 100644 --- a/core/src/services/lakefs/core.rs +++ b/core/src/services/lakefs/core.rs @@ -171,6 +171,29 @@ impl LakefsCore { self.client.send(req).await } + + pub async fn delete_object(&self, path: &str, _args: &OpDelete) -> Result> { + let p = build_abs_path(&self.root, path) + .trim_end_matches('/') + .to_string(); + + let url = format!( + "{}/api/v1/repositories/{}/branches/{}/objects?path={}", + self.endpoint, + self.repository, + self.branch, + percent_encode_path(&p) + ); + + let mut req = Request::delete(&url); + + let auth_header_content = format_authorization_by_basic(&self.username, &self.password)?; + req = req.header(header::AUTHORIZATION, auth_header_content); + + let req = req.body(Buffer::new()).map_err(new_request_build_error)?; + + self.client.send(req).await + } } #[derive(Deserialize, Eq, PartialEq, Debug)] diff --git a/core/src/services/lakefs/docs.md b/core/src/services/lakefs/docs.md index 892bf66b176..662787964f2 100644 --- a/core/src/services/lakefs/docs.md +++ b/core/src/services/lakefs/docs.md @@ -11,7 +11,7 @@ This service can be used to: - [x] read - [x] write - [ ] create_dir -- [ ] delete +- [x] delete - [ ] copy - [ ] rename - [x] list