You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opendal.apache.org by xu...@apache.org on 2024/01/17 09:00:44 UTC
(incubator-opendal) 02/02: Use trash instead of delete
This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch gdrive
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 6fea652ac9cd885910d2eaa7af0336af1dc0e467
Author: Xuanwo <gi...@xuanwo.io>
AuthorDate: Wed Jan 17 17:00:29 2024 +0800
Use trash instead of delete
Signed-off-by: Xuanwo <gi...@xuanwo.io>
---
core/src/services/gdrive/backend.rs | 6 +++---
core/src/services/gdrive/core.rs | 11 ++++++++---
2 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/core/src/services/gdrive/backend.rs b/core/src/services/gdrive/backend.rs
index ed9ed8354e..7b50d852a2 100644
--- a/core/src/services/gdrive/backend.rs
+++ b/core/src/services/gdrive/backend.rs
@@ -148,7 +148,7 @@ impl Accessor for GdriveBackend {
return Ok(RpDelete::default());
};
- let resp = self.core.gdrive_delete(&file_id).await?;
+ let resp = self.core.gdrive_trash(&file_id).await?;
let status = resp.status();
if status != StatusCode::NO_CONTENT && status != StatusCode::NOT_FOUND {
return Err(parse_error(resp).await?);
@@ -183,7 +183,7 @@ impl Accessor for GdriveBackend {
// copy will overwrite `to`, delete it if exist
if let Some(id) = self.core.path_cache.get(&to_path).await? {
- let resp = self.core.gdrive_delete(&id).await?;
+ let resp = self.core.gdrive_trash(&id).await?;
let status = resp.status();
if status != StatusCode::NO_CONTENT && status != StatusCode::NOT_FOUND {
return Err(parse_error(resp).await?);
@@ -223,7 +223,7 @@ impl Accessor for GdriveBackend {
// rename will overwrite `to`, delete it if exist
if let Some(id) = self.core.path_cache.get(&target).await? {
- let resp = self.core.gdrive_delete(&id).await?;
+ let resp = self.core.gdrive_trash(&id).await?;
let status = resp.status();
if status != StatusCode::NO_CONTENT && status != StatusCode::NOT_FOUND {
return Err(parse_error(resp).await?);
diff --git a/core/src/services/gdrive/core.rs b/core/src/services/gdrive/core.rs
index 73685b8632..96ad5f1e11 100644
--- a/core/src/services/gdrive/core.rs
+++ b/core/src/services/gdrive/core.rs
@@ -161,11 +161,16 @@ impl GdriveCore {
self.client.send(req).await
}
- pub async fn gdrive_delete(&self, file_id: &str) -> Result<Response<IncomingAsyncBody>> {
+ pub async fn gdrive_trash(&self, file_id: &str) -> Result<Response<IncomingAsyncBody>> {
let url = format!("https://www.googleapis.com/drive/v3/files/{}", file_id);
- let mut req = Request::delete(&url)
- .body(AsyncBody::Empty)
+ let body = serde_json::to_vec(&json!({
+ "trashed": true
+ }))
+ .map_err(new_json_serialize_error)?;
+
+ let mut req = Request::patch(&url)
+ .body(AsyncBody::Bytes(Bytes::from(body)))
.map_err(new_request_build_error)?;
self.sign(&mut req).await?;