Skip to content

Commit

Permalink
fix(services/webdav): Fix endpoint suffix not handled (#4257)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
Xuanwo authored Feb 23, 2024
1 parent f6a161b commit d444649
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 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
17 changes: 15 additions & 2 deletions core/src/services/webdav/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,29 @@

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()
.trim_end_matches('/')
.to_string();
Self {
server_path,
root: root.into(),
path: path.into(),
multistates,
Expand All @@ -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 {
Expand Down

0 comments on commit d444649

Please sign in to comment.