diff --git a/core/src/services/webdav/backend.rs b/core/src/services/webdav/backend.rs index fd2edaf1545e..781ed36c5130 100644 --- a/core/src/services/webdav/backend.rs +++ b/core/src/services/webdav/backend.rs @@ -301,7 +301,7 @@ impl Accessor for WebdavBackend { return Err(Error::new( ErrorKind::NotFound, "Failed getting item stat: response field was not found", - )) + )); } }; @@ -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)))) } diff --git a/core/src/services/webdav/lister.rs b/core/src/services/webdav/lister.rs index d4d0241f3e77..fa125711ba6b 100644 --- a/core/src/services/webdav/lister.rs +++ b/core/src/services/webdav/lister.rs @@ -17,10 +17,13 @@ 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, @@ -28,8 +31,15 @@ pub struct WebdavLister { 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() + .trim_end_matches('/') + .to_string(); Self { + server_path, root: root.into(), path: path.into(), multistates, @@ -44,7 +54,10 @@ 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 + .strip_prefix(&self.server_path) + .unwrap_or(&res.href); // Ignore the root path itself. if self.root == path {