Skip to content

Commit

Permalink
fix(services/webdav): remove base_dir component (#4231)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoslo authored Feb 21, 2024
1 parent 332a437 commit 7303f78
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 20 deletions.
14 changes: 1 addition & 13 deletions core/src/services/webdav/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ use std::collections::HashMap;
use std::collections::VecDeque;
use std::fmt::Debug;
use std::fmt::Formatter;
use std::str::FromStr;

use async_trait::async_trait;
use bytes::Buf;
Expand Down Expand Up @@ -180,15 +179,6 @@ impl Builder for WebdavBuilder {
}
};

let uri = http::Uri::from_str(endpoint).map_err(|err| {
Error::new(ErrorKind::ConfigInvalid, "endpoint is invalid")
.set_source(err)
.with_context("service", Scheme::Webdav)
})?;
// Some webdav server may have base dir like `/remote.php/webdav/`
// returned in the `href`.
let base_dir = uri.path().trim_end_matches('/');

let root = normalize_root(&self.config.root.take().unwrap_or_default());
debug!("backend use root {}", root);

Expand All @@ -215,7 +205,6 @@ impl Builder for WebdavBuilder {
debug!("backend build finished: {:?}", &self);
Ok(WebdavBackend {
endpoint: endpoint.to_string(),
base_dir: base_dir.to_string(),
authorization: auth,
root,
client,
Expand All @@ -227,7 +216,6 @@ impl Builder for WebdavBuilder {
#[derive(Clone)]
pub struct WebdavBackend {
endpoint: String,
base_dir: String,
root: String,
client: HttpClient,

Expand Down Expand Up @@ -391,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.base_dir, &self.root, path, result);
let l = WebdavLister::new(&self.root, path, result);

Ok((RpList::default(), Some(oio::PageLister::new(l))))
}
Expand Down
9 changes: 2 additions & 7 deletions core/src/services/webdav/lister.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,17 +21,15 @@ use serde::Deserialize;
use crate::raw::*;
use crate::*;
pub struct WebdavLister {
base_dir: String,
root: String,
path: String,
multistates: Multistatus,
}

impl WebdavLister {
/// TODO: sending request in `next_page` instead of in `new`.
pub fn new(base_dir: &str, root: &str, path: &str, multistates: Multistatus) -> Self {
pub fn new(root: &str, path: &str, multistates: Multistatus) -> Self {
Self {
base_dir: base_dir.to_string(),
root: root.into(),
path: path.into(),
multistates,
Expand All @@ -46,10 +44,7 @@ impl oio::PageList for WebdavLister {
let oes = self.multistates.response.clone();

for res in oes {
let path = res
.href
.strip_prefix(&self.base_dir)
.unwrap_or(res.href.as_str());
let path = res.href.as_str();

// Ignore the root path itself.
if self.root == path {
Expand Down

0 comments on commit 7303f78

Please sign in to comment.