Skip to content
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
13 changes: 11 additions & 2 deletions core/services/swift/src/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,16 @@ impl Builder for SwiftBuilder {
.set_root(&root)
.set_native_capability(Capability {
stat: true,
stat_with_if_match: true,
stat_with_if_none_match: true,
stat_with_if_modified_since: true,
stat_with_if_unmodified_since: true,

read: true,
read_with_if_match: true,
read_with_if_none_match: true,
read_with_if_modified_since: true,
read_with_if_unmodified_since: true,

write: true,
write_can_empty: true,
Expand Down Expand Up @@ -186,8 +195,8 @@ impl Access for SwiftBackend {
self.core.info.clone()
}

async fn stat(&self, path: &str, _args: OpStat) -> Result<RpStat> {
let resp = self.core.swift_get_metadata(path).await?;
async fn stat(&self, path: &str, args: OpStat) -> Result<RpStat> {
let resp = self.core.swift_get_metadata(path, &args).await?;

match resp.status() {
StatusCode::OK | StatusCode::NO_CONTENT => {
Expand Down
34 changes: 32 additions & 2 deletions core/services/swift/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ use std::sync::Arc;
use http::Request;
use http::Response;
use http::header;
use http::header::IF_MATCH;
use http::header::IF_MODIFIED_SINCE;
use http::header::IF_NONE_MATCH;
use http::header::IF_UNMODIFIED_SINCE;
use serde::Deserialize;

use opendal_core::raw::*;
Expand Down Expand Up @@ -143,7 +147,7 @@ impl SwiftCore {
&self,
path: &str,
range: BytesRange,
_arg: &OpRead,
args: &OpRead,
) -> Result<Response<HttpBody>> {
let p = build_abs_path(&self.root, path)
.trim_end_matches('/')
Expand All @@ -164,6 +168,19 @@ impl SwiftCore {
req = req.header(header::RANGE, range.to_header());
}

if let Some(if_match) = args.if_match() {
req = req.header(IF_MATCH, if_match);
}
if let Some(if_none_match) = args.if_none_match() {
req = req.header(IF_NONE_MATCH, if_none_match);
}
if let Some(if_modified_since) = args.if_modified_since() {
req = req.header(IF_MODIFIED_SINCE, if_modified_since.format_http_date());
}
if let Some(if_unmodified_since) = args.if_unmodified_since() {
req = req.header(IF_UNMODIFIED_SINCE, if_unmodified_since.format_http_date());
}

let req = req
.extension(Operation::Read)
.body(Buffer::new())
Expand Down Expand Up @@ -212,7 +229,7 @@ impl SwiftCore {
self.info.http_client().send(req).await
}

pub async fn swift_get_metadata(&self, path: &str) -> Result<Response<Buffer>> {
pub async fn swift_get_metadata(&self, path: &str, args: &OpStat) -> Result<Response<Buffer>> {
let p = build_abs_path(&self.root, path);

let url = format!(
Expand All @@ -226,6 +243,19 @@ impl SwiftCore {

req = req.header("X-Auth-Token", &self.token);

if let Some(if_match) = args.if_match() {
req = req.header(IF_MATCH, if_match);
}
if let Some(if_none_match) = args.if_none_match() {
req = req.header(IF_NONE_MATCH, if_none_match);
}
if let Some(if_modified_since) = args.if_modified_since() {
req = req.header(IF_MODIFIED_SINCE, if_modified_since.format_http_date());
}
if let Some(if_unmodified_since) = args.if_unmodified_since() {
req = req.header(IF_UNMODIFIED_SINCE, if_unmodified_since.format_http_date());
}

let req = req
.extension(Operation::Stat)
.body(Buffer::new())
Expand Down
4 changes: 3 additions & 1 deletion core/services/swift/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ pub(super) fn parse_error(resp: Response<Buffer>) -> Error {
let (kind, retryable) = match parts.status {
StatusCode::NOT_FOUND => (ErrorKind::NotFound, false),
StatusCode::UNAUTHORIZED | StatusCode::FORBIDDEN => (ErrorKind::PermissionDenied, false),
StatusCode::PRECONDITION_FAILED => (ErrorKind::ConditionNotMatch, false),
StatusCode::NOT_MODIFIED | StatusCode::PRECONDITION_FAILED => {
(ErrorKind::ConditionNotMatch, false)
}
StatusCode::INTERNAL_SERVER_ERROR
| StatusCode::BAD_GATEWAY
| StatusCode::SERVICE_UNAVAILABLE
Expand Down
Loading