Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove metakey concept #5319

Merged
merged 3 commits into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions bin/oay/src/services/s3/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ use axum::routing::get;
use axum::Router;
use chrono::SecondsFormat;
use futures_util::StreamExt;
use opendal::Metakey;
use opendal::Operator;
use serde::Deserialize;
use serde::Serialize;
Expand Down Expand Up @@ -100,7 +99,6 @@ async fn handle_list_objects(
.op
.lister_with(&params.prefix)
.start_after(&params.start_after)
.metakey(Metakey::Mode | Metakey::LastModified | Metakey::Etag | Metakey::ContentLength)
.await?
.chunks(1000);

Expand Down
2 changes: 1 addition & 1 deletion bindings/java/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ impl From<opendal::Error> for Error {

impl From<jni::errors::Error> for Error {
fn from(err: jni::errors::Error) -> Self {
opendal::Error::new(ErrorKind::Unexpected, &err.to_string()).into()
opendal::Error::new(ErrorKind::Unexpected, err.to_string()).into()
}
}

Expand Down
85 changes: 24 additions & 61 deletions bindings/java/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ use opendal::Capability;
use opendal::Entry;
use opendal::EntryMode;
use opendal::Metadata;
use opendal::Metakey;
use opendal::OperatorInfo;

mod async_operator;
Expand All @@ -51,7 +50,7 @@ fn make_presigned_request<'a>(env: &mut JNIEnv<'a>, req: PresignedRequest) -> Re
for (k, v) in req.header().iter() {
let key = k.to_string();
let value = v.to_str().map_err(|err| {
opendal::Error::new(opendal::ErrorKind::Unexpected, &err.to_string())
opendal::Error::new(opendal::ErrorKind::Unexpected, err.to_string())
})?;
map.insert(key, value.to_owned());
}
Expand Down Expand Up @@ -143,72 +142,36 @@ fn make_metadata<'a>(env: &mut JNIEnv<'a>, metadata: Metadata) -> Result<JObject
EntryMode::Unknown => 2,
};

let metakey = metadata.metakey();

let contains_metakey = |k| metakey.contains(k) || metakey.contains(Metakey::Complete);

let last_modified = if contains_metakey(Metakey::LastModified) {
metadata.last_modified().map_or_else(
|| Ok::<JObject<'_>, error::Error>(JObject::null()),
|v| {
Ok(env
.call_static_method(
"java/time/Instant",
"ofEpochSecond",
"(JJ)Ljava/time/Instant;",
&[
JValue::Long(v.timestamp()),
JValue::Long(v.timestamp_subsec_nanos() as jlong),
],
)?
.l()?)
},
)?
} else {
JObject::null()
};
let last_modified = metadata.last_modified().map_or_else(
|| Ok::<JObject<'_>, error::Error>(JObject::null()),
|v| {
Ok(env
.call_static_method(
"java/time/Instant",
"ofEpochSecond",
"(JJ)Ljava/time/Instant;",
&[
JValue::Long(v.timestamp()),
JValue::Long(v.timestamp_subsec_nanos() as jlong),
],
)?
.l()?)
},
)?;

let cache_control = if contains_metakey(Metakey::CacheControl) {
convert::string_to_jstring(env, metadata.cache_control())?
} else {
JObject::null()
};
let cache_control = convert::string_to_jstring(env, metadata.cache_control())?;

let content_disposition = if contains_metakey(Metakey::ContentDisposition) {
convert::string_to_jstring(env, metadata.content_disposition())?
} else {
JObject::null()
};
let content_disposition = convert::string_to_jstring(env, metadata.content_disposition())?;

let content_md5 = if contains_metakey(Metakey::ContentMd5) {
convert::string_to_jstring(env, metadata.content_md5())?
} else {
JObject::null()
};
let content_md5 = convert::string_to_jstring(env, metadata.content_md5())?;

let content_type = if contains_metakey(Metakey::ContentType) {
convert::string_to_jstring(env, metadata.content_type())?
} else {
JObject::null()
};
let content_type = convert::string_to_jstring(env, metadata.content_type())?;

let etag = if contains_metakey(Metakey::Etag) {
convert::string_to_jstring(env, metadata.etag())?
} else {
JObject::null()
};
let etag = convert::string_to_jstring(env, metadata.etag())?;

let version = if contains_metakey(Metakey::Version) {
convert::string_to_jstring(env, metadata.version())?
} else {
JObject::null()
};
let version = convert::string_to_jstring(env, metadata.version())?;

let content_length = if contains_metakey(Metakey::ContentLength) {
metadata.content_length() as jlong
} else {
-1
};
let content_length = metadata.content_length() as jlong;

let result = env
.new_object(
Expand Down
2 changes: 1 addition & 1 deletion bindings/java/src/operator_input_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ fn intern_read_next_bytes(
match reader
.next()
.transpose()
.map_err(|err| opendal::Error::new(opendal::ErrorKind::Unexpected, &err.to_string()))?
.map_err(|err| opendal::Error::new(opendal::ErrorKind::Unexpected, err.to_string()))?
{
None => Ok(JObject::null().into_raw()),
Some(content) => {
Expand Down
7 changes: 0 additions & 7 deletions core/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading