This is an automated email from the ASF dual-hosted git repository.
xuanwo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opendal.git
The following commit(s) were added to refs/heads/main by this push:
new d444649423 fix(services/webdav): Fix endpoint suffix not handled
(#4257)
d444649423 is described below
commit d4446494239a43bb34149f907130a894024942d2
Author: Xuanwo <[email protected]>
AuthorDate: Fri Feb 23 14:00:59 2024 +0800
fix(services/webdav): Fix endpoint suffix not handled (#4257)
* fix(services/webdav): Fix endpoint suffix not handled
Signed-off-by: Xuanwo <[email protected]>
* Format code
Signed-off-by: Xuanwo <[email protected]>
* Fix build
Signed-off-by: Xuanwo <[email protected]>
* Fix build
Signed-off-by: Xuanwo <[email protected]>
* fix typo
Signed-off-by: Xuanwo <[email protected]>
* Fix build
Signed-off-by: Xuanwo <[email protected]>
---------
Signed-off-by: Xuanwo <[email protected]>
---
core/src/services/webdav/backend.rs | 4 ++--
core/src/services/webdav/lister.rs | 17 +++++++++++++++--
2 files changed, 17 insertions(+), 4 deletions(-)
diff --git a/core/src/services/webdav/backend.rs
b/core/src/services/webdav/backend.rs
index fd2edaf154..781ed36c51 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 d4d0241f3e..fa125711ba 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 {