Skip to content

Commit

Permalink
fix(services/webdav): Fix endpoint suffix not handled
Browse files Browse the repository at this point in the history
Signed-off-by: Xuanwo <[email protected]>
  • Loading branch information
Xuanwo committed Feb 23, 2024
1 parent f6a161b commit dfbf80b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 15 deletions.
4 changes: 2 additions & 2 deletions core/src/services/webdav/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ impl Accessor for WebdavBackend {
return Err(Error::new(
ErrorKind::NotFound,
"Failed getting item stat: response field was not found",
))
));
}
};

Expand Down Expand Up @@ -379,7 +379,7 @@ impl Accessor for WebdavBackend {
let result: Multistatus =
quick_xml::de::from_reader(bs.reader()).map_err(new_xml_deserialize_error)?;

let l = WebdavLister::new(&self.root, path, result);
let l = WebdavLister::new(&self.endpoint, &self.root, path, result);

Ok((RpList::default(), Some(oio::PageLister::new(l))))
}
Expand Down
35 changes: 22 additions & 13 deletions core/src/services/webdav/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,28 @@

use async_trait::async_trait;
use serde::Deserialize;
use std::str::FromStr;

use crate::raw::*;
use crate::*;

pub struct WebdavLister {
server_path: String,
root: String,
path: String,
multistates: Multistatus,
}

impl WebdavLister {
/// TODO: sending request in `next_page` instead of in `new`.
pub fn new(root: &str, path: &str, multistates: Multistatus) -> Self {
pub fn new(endpoint: &str, root: &str, path: &str, multistates: Multistatus) -> Self {
// Some services might return the path with suffix `/remote.php/webdav/`, we need to trim them.
let server_path = http::Uri::from_str(endpoint)
.expect("must be valid http uri")
.path()
.to_string();
Self {
server_path,
root: root.into(),
path: path.into(),
multistates,
Expand All @@ -44,7 +53,7 @@ impl oio::PageList for WebdavLister {
let oes = self.multistates.response.clone();

for res in oes {
let path = res.href.as_str();
let path = res.href.trim_start_matches(&self.server_path);

// Ignore the root path itself.
if self.root == path {
Expand Down Expand Up @@ -88,18 +97,18 @@ impl ListOpResponse {
pub fn parse_into_metadata(&self) -> Result<Metadata> {
let ListOpResponse {
propstat:
Propstat {
prop:
Prop {
getlastmodified,
getcontentlength,
getcontenttype,
getetag,
resourcetype,
..
},
status,
Propstat {
prop:
Prop {
getlastmodified,
getcontentlength,
getcontenttype,
getetag,
resourcetype,
..
},
status,
},
..
} = self;
if let [_, code, text] = status.split(' ').collect::<Vec<_>>()[..3] {
Expand Down

0 comments on commit dfbf80b

Please sign in to comment.