This is an automated email from the ASF dual-hosted git repository. xuanwo pushed a commit to branch fix-stat in repository https://gitbox.apache.org/repos/asf/incubator-opendal.git
commit 592161be02c4f5743761ce1771d77da44cf5d9db Author: Xuanwo <[email protected]> AuthorDate: Tue Nov 21 19:49:12 2023 +0800 Fix azdls Signed-off-by: Xuanwo <[email protected]> --- core/benches/vs_s3/src/main.rs | 6 ++-- core/src/raw/oio/list/flat_list.rs | 2 +- core/src/services/azblob/backend.rs | 3 +- core/src/services/azblob/core.rs | 5 +-- core/src/services/azblob/lister.rs | 3 +- core/src/services/azdls/backend.rs | 48 ++++++++++++++++++++++++---- core/src/services/s3/lister.rs | 3 +- core/src/types/operator/blocking_operator.rs | 3 +- 8 files changed, 57 insertions(+), 16 deletions(-) diff --git a/core/benches/vs_s3/src/main.rs b/core/benches/vs_s3/src/main.rs index d2d9aec68..b8fd9c3fb 100644 --- a/core/benches/vs_s3/src/main.rs +++ b/core/benches/vs_s3/src/main.rs @@ -15,14 +15,16 @@ // specific language governing permissions and limitations // under the License. -use aws_config::{BehaviorVersion, Region}; +use std::env; + +use aws_config::BehaviorVersion; +use aws_config::Region; use aws_credential_types::Credentials; use criterion::Criterion; use opendal::raw::tests::TEST_RUNTIME; use opendal::services; use opendal::Operator; use rand::prelude::*; -use std::env; use tokio::io::AsyncReadExt; fn main() { diff --git a/core/src/raw/oio/list/flat_list.rs b/core/src/raw/oio/list/flat_list.rs index 3328c74b8..e6363bf80 100644 --- a/core/src/raw/oio/list/flat_list.rs +++ b/core/src/raw/oio/list/flat_list.rs @@ -208,11 +208,11 @@ where #[cfg(test)] mod tests { - use async_trait::async_trait; use std::collections::HashMap; use std::vec; use std::vec::IntoIter; + use async_trait::async_trait; use log::debug; use oio::BlockingList; diff --git a/core/src/services/azblob/backend.rs b/core/src/services/azblob/backend.rs index 42548154c..6d728c081 100644 --- a/core/src/services/azblob/backend.rs +++ b/core/src/services/azblob/backend.rs @@ -38,7 +38,8 @@ use super::error::parse_error; use super::lister::AzblobLister; use super::writer::AzblobWriter; use crate::raw::*; -use crate::services::azblob::core::{AzblobCore, ListBlobsOutput}; +use crate::services::azblob::core::AzblobCore; +use crate::services::azblob::core::ListBlobsOutput; use crate::services::azblob::writer::AzblobWriters; use crate::types::Metadata; use crate::*; diff --git a/core/src/services/azblob/core.rs b/core/src/services/azblob/core.rs index 63a003f2d..64420683d 100644 --- a/core/src/services/azblob/core.rs +++ b/core/src/services/azblob/core.rs @@ -577,10 +577,11 @@ pub struct Properties { #[cfg(test)] mod tests { - use bytes::{Buf, Bytes}; + use bytes::Buf; + use bytes::Bytes; + use quick_xml::de; use super::*; - use quick_xml::de; #[test] fn test_parse_xml() { diff --git a/core/src/services/azblob/lister.rs b/core/src/services/azblob/lister.rs index ad78e655a..2a02ce2bd 100644 --- a/core/src/services/azblob/lister.rs +++ b/core/src/services/azblob/lister.rs @@ -21,7 +21,8 @@ use async_trait::async_trait; use bytes::Buf; use quick_xml::de; -use super::core::{AzblobCore, ListBlobsOutput}; +use super::core::AzblobCore; +use super::core::ListBlobsOutput; use super::error::parse_error; use crate::raw::*; use crate::*; diff --git a/core/src/services/azdls/backend.rs b/core/src/services/azdls/backend.rs index b1a7366e0..7a51a5220 100644 --- a/core/src/services/azdls/backend.rs +++ b/core/src/services/azdls/backend.rs @@ -343,15 +343,49 @@ impl Accessor for AzdlsBackend { let resp = self.core.azdls_get_properties(path).await?; - let status = resp.status(); + if resp.status() != StatusCode::OK { + return Err(parse_error(resp).await?); + } - match status { - StatusCode::OK => parse_into_metadata(path, resp.headers()).map(RpStat::new), - StatusCode::NOT_FOUND if path.ends_with('/') => { - Ok(RpStat::new(Metadata::new(EntryMode::DIR))) - } - _ => Err(parse_error(resp).await?), + let mut meta = parse_into_metadata(path, resp.headers())?; + let resource = resp + .headers() + .get("x-ms-resource-type") + .ok_or_else(|| { + Error::new( + ErrorKind::Unexpected, + "azdls should return x-ms-resource-type header, but it's missing", + ) + })? + .to_str() + .map_err(|err| { + Error::new( + ErrorKind::Unexpected, + "azdls should return x-ms-resource-type header, but it's not a valid string", + ) + .set_source(err) + })?; + + if path.ends_with('/') && resource == "file" { + return Err(Error::new( + ErrorKind::NotFound, + "azdls has this file, but it should not be stated as a directory", + )); } + + meta = match resource { + "file" => meta.with_mode(EntryMode::FILE), + "directory" => meta.with_mode(EntryMode::DIR), + v => { + return Err(Error::new( + ErrorKind::Unexpected, + "azdls returns not supported x-ms-resource-type", + ) + .with_context("resource", v)) + } + }; + + Ok(RpStat::new(meta)) } async fn delete(&self, path: &str, _: OpDelete) -> Result<RpDelete> { diff --git a/core/src/services/s3/lister.rs b/core/src/services/s3/lister.rs index cab972c1f..2c05edaa6 100644 --- a/core/src/services/s3/lister.rs +++ b/core/src/services/s3/lister.rs @@ -21,7 +21,8 @@ use async_trait::async_trait; use bytes::Buf; use quick_xml::de; -use super::core::{Output, S3Core}; +use super::core::Output; +use super::core::S3Core; use super::error::parse_error; use crate::raw::*; use crate::EntryMode; diff --git a/core/src/types/operator/blocking_operator.rs b/core/src/types/operator/blocking_operator.rs index 0659efe8f..a4165fd10 100644 --- a/core/src/types/operator/blocking_operator.rs +++ b/core/src/types/operator/blocking_operator.rs @@ -18,7 +18,8 @@ use bytes::Bytes; use super::operator_functions::*; -use crate::raw::oio::{BlockingRead, WriteBuf}; +use crate::raw::oio::BlockingRead; +use crate::raw::oio::WriteBuf; use crate::raw::*; use crate::*;
