This is an automated email from the ASF dual-hosted git repository.
suyanhanx pushed a commit to branch gdrive
in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
The following commit(s) were added to refs/heads/gdrive by this push:
new 110053730 sort
110053730 is described below
commit 110053730ea14ca3437626e6d62cb96f83ae4006
Author: suyanhanx <[email protected]>
AuthorDate: Mon Aug 21 18:07:25 2023 +0800
sort
Signed-off-by: suyanhanx <[email protected]>
---
Cargo.lock | 1 -
core/Cargo.toml | 1 -
core/src/raw/http_util/client.rs | 84 -------------------------------------
core/src/services/gdrive/backend.rs | 24 +++++------
4 files changed, 11 insertions(+), 99 deletions(-)
diff --git a/Cargo.lock b/Cargo.lock
index ec5c2aca9..ea91cdd01 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -4884,7 +4884,6 @@ dependencies = [
"js-sys",
"log",
"mime",
- "mime_guess",
"native-tls",
"once_cell",
"percent-encoding",
diff --git a/core/Cargo.toml b/core/Cargo.toml
index 313d568b0..b46cf3494 100644
--- a/core/Cargo.toml
+++ b/core/Cargo.toml
@@ -249,7 +249,6 @@ redis = { version = "0.23.1", features = [
reqsign = { version = "0.14.1", default-features = false, optional = true }
reqwest = { version = "0.11.18", features = [
"stream",
- "multipart",
], default-features = false }
rocksdb = { version = "0.21.0", default-features = false, optional = true }
serde = { version = "1", features = ["derive"] }
diff --git a/core/src/raw/http_util/client.rs b/core/src/raw/http_util/client.rs
index 1738468eb..9578af9ce 100644
--- a/core/src/raw/http_util/client.rs
+++ b/core/src/raw/http_util/client.rs
@@ -23,7 +23,6 @@ use std::str::FromStr;
use futures::TryStreamExt;
use http::Request;
use http::Response;
-use reqwest::multipart::Form;
use super::body::IncomingAsyncBody;
use super::parse_content_length;
@@ -157,87 +156,4 @@ impl HttpClient {
Ok(resp)
}
-
- /// Send a request in async way.
- ///
- /// For a request with form data, there could be different types of data
- /// in the form, so we need to use `Form` to represent it.
- pub async fn send_form_data(&self, req: Request<Form>) ->
Result<Response<IncomingAsyncBody>> {
- // Uri stores all string alike data in `Bytes` which means
- // the clone here is cheap.
- let uri = req.uri().clone();
- let is_head = req.method() == http::Method::HEAD;
-
- let (parts, body) = req.into_parts();
-
- let mut req_builder = self
- .client
- .request(
- parts.method,
- reqwest::Url::from_str(&uri.to_string()).expect("input request
url must be valid"),
- )
- .version(parts.version)
- .headers(parts.headers);
-
- // Because the inner data's type will be set when we
- // append it to the form, we just re-use the `body` here.
- req_builder = req_builder.multipart(body);
-
- let mut resp = req_builder.send().await.map_err(|err| {
- let is_temporary = !(
- // Builder related error should not be retried.
- err.is_builder() ||
- // Error returned by RedirectPolicy.
- //
- // We don't set this by hand, just don't allow retry.
- err.is_redirect() ||
- // We never use `Response::error_for_status`, just don't
allow retry.
- //
- // Status should be checked by our services.
- err.is_status()
- );
-
- let mut oerr = Error::new(ErrorKind::Unexpected, "send async
request")
- .with_operation("http_util::Client::send_async")
- .with_context("url", uri.to_string())
- .set_source(err);
- if is_temporary {
- oerr = oerr.set_temporary();
- }
-
- oerr
- })?;
-
- // Get content length from header so that we can check it.
- // If the request method is HEAD, we will ignore this.
- let content_length = if is_head {
- None
- } else {
- parse_content_length(resp.headers()).expect("response content
length must be valid")
- };
-
- let mut hr = Response::builder()
- .version(resp.version())
- .status(resp.status())
- // Insert uri into response extension so that we can fetch
- // it later.
- .extension(uri.clone());
- // Swap headers directly instead of copy the entire map.
- mem::swap(hr.headers_mut().unwrap(), resp.headers_mut());
-
- let stream = resp.bytes_stream().map_err(move |err| {
- // If stream returns a body related error, we can convert
- // it to interrupt so we can retry it.
- Error::new(ErrorKind::Unexpected, "read data from http stream")
- .map(|v| if err.is_body() { v.set_temporary() } else { v })
- .with_context("url", uri.to_string())
- .set_source(err)
- });
-
- let body = IncomingAsyncBody::new(Box::new(oio::into_stream(stream)),
content_length);
-
- let resp = hr.body(body).expect("response must build succeed");
-
- Ok(resp)
- }
}
diff --git a/core/src/services/gdrive/backend.rs
b/core/src/services/gdrive/backend.rs
index be49b8ddf..0e322545e 100644
--- a/core/src/services/gdrive/backend.rs
+++ b/core/src/services/gdrive/backend.rs
@@ -170,8 +170,7 @@ impl Accessor for GdriveBackend {
let resp = self.core.gdrive_stat(path).await;
// We don't care about the error here.
// As long as the file doesn't exist, we will create a new one.
- if resp.is_ok() {
- let resp = resp.unwrap();
+ if let Ok(resp) = resp {
let status = resp.status();
if status == StatusCode::OK {
@@ -195,21 +194,20 @@ impl Accessor for GdriveBackend {
async fn delete(&self, path: &str, _: OpDelete) -> Result<RpDelete> {
let resp = self.core.gdrive_delete(path).await;
- if resp.is_err() {
- let e = resp.err().unwrap();
- if e.kind() == ErrorKind::NotFound {
- return Ok(RpDelete::default());
- } else {
- return Err(e);
- }
- } else {
- let resp = resp.unwrap();
+ if let Ok(resp) = resp {
let status = resp.status();
match status {
- StatusCode::NO_CONTENT => Ok(RpDelete::default()),
- _ => Err(parse_error(resp).await?),
+ StatusCode::NO_CONTENT => return Ok(RpDelete::default()),
+ _ => return Err(parse_error(resp).await?),
}
+ };
+
+ let e = resp.err().unwrap();
+ if e.kind() == ErrorKind::NotFound {
+ Ok(RpDelete::default())
+ } else {
+ Err(e)
}
}
}