Skip to content

Commit

Permalink
refine lock & clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
imWildCat committed Feb 13, 2023
1 parent 3ae73a2 commit d99af6c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 99 deletions.
5 changes: 1 addition & 4 deletions src/services/webdav/backend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,10 +292,7 @@ impl Accessor for WebdavBackend {
.with_context("service", Scheme::Webdav)
})?;

Ok((
RpList::default(),
DirStream::new(self.root.clone(), result, args.limit()),
))
Ok((RpList::default(), DirStream::new(result, args.limit())))
}
_ => Err(parse_error(resp).await?), // TODO: handle error gracefully
}
Expand Down
5 changes: 1 addition & 4 deletions src/services/webdav/dir_stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ use async_trait::async_trait;
use super::list_response::Multistatus;

pub struct DirStream {
root: String,

size: usize,
multistates: Multistatus,
}

impl DirStream {
pub fn new(root: String, multistates: Multistatus, limit: Option<usize>) -> Self {
pub fn new(multistates: Multistatus, limit: Option<usize>) -> Self {
Self {
root: root.to_owned(),
size: limit.unwrap_or(1000),
multistates: multistates,
}
Expand Down
92 changes: 1 addition & 91 deletions src/services/webdav/list_response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,6 @@

use serde::Deserialize;

#[derive(Deserialize, Debug, PartialEq)]
#[serde(rename_all = "lowercase")]
pub struct LockEntry {
pub lockscope: LockScopeContainer,
pub locktype: LockTypeContainer,
}

#[derive(Deserialize, Debug, PartialEq)]
pub struct LockScopeContainer {
#[serde(rename = "$value")]
Expand Down Expand Up @@ -68,7 +61,6 @@ pub struct Prop {
pub getlastmodified: String,
pub resourcetype: ResourceTypeContainer,
pub lockdiscovery: (),
pub supportedlock: SupportedLock,
}

#[derive(Deserialize, Debug, PartialEq)]
Expand All @@ -83,44 +75,10 @@ pub enum ResourceType {
Collection,
}

#[derive(Deserialize, Debug, PartialEq)]

pub struct SupportedLock {
lockentry: LockEntry,
}

#[cfg(test)]
mod tests {
use super::*;
use quick_xml::de::from_str;
#[test]
fn test_lockentry() {
let xml = r#"<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>"#;

let lockentry = from_str::<LockEntry>(xml).unwrap();
assert_eq!(lockentry.lockscope.value, LockScope::Exclusive);
assert_eq!(lockentry.locktype.value, LockType::Write);
}

#[test]
fn test_supportedlock() {
let xml = r#"<D:supportedlock>
<D:lockentry>
<D:lockscope><D:exclusive/></D:lockscope>
<D:locktype><D:write/></D:locktype>
</D:lockentry>
</D:supportedlock>"#;

let supportedlock = from_str::<SupportedLock>(xml).unwrap();
assert_eq!(
supportedlock.lockentry.lockscope.value,
LockScope::Exclusive
);
assert_eq!(supportedlock.lockentry.locktype.value, LockType::Write);
}

#[test]
fn test_propstat() {
Expand Down Expand Up @@ -150,14 +108,7 @@ mod tests {
propstat.prop.resourcetype.value.unwrap(),
ResourceType::Collection
);
assert_eq!(
propstat.prop.supportedlock.lockentry.lockscope.value,
LockScope::Exclusive
);
assert_eq!(
propstat.prop.supportedlock.lockentry.locktype.value,
LockType::Write
);

assert_eq!(propstat.status, "HTTP/1.1 200 OK");
}

Expand Down Expand Up @@ -193,26 +144,6 @@ mod tests {
response.propstat.prop.resourcetype.value.unwrap(),
ResourceType::Collection
);
assert_eq!(
response
.propstat
.prop
.supportedlock
.lockentry
.lockscope
.value,
LockScope::Exclusive
);
assert_eq!(
response
.propstat
.prop
.supportedlock
.lockentry
.locktype
.value,
LockType::Write
);
assert_eq!(response.propstat.status, "HTTP/1.1 200 OK");
}

Expand Down Expand Up @@ -250,27 +181,6 @@ mod tests {
"Tue, 07 May 2022 05:52:22 GMT"
);
assert_eq!(response.propstat.prop.resourcetype.value, None);

assert_eq!(
response
.propstat
.prop
.supportedlock
.lockentry
.lockscope
.value,
LockScope::Exclusive
);
assert_eq!(
response
.propstat
.prop
.supportedlock
.lockentry
.locktype
.value,
LockType::Write
);
assert_eq!(response.propstat.status, "HTTP/1.1 200 OK");
}

Expand Down

0 comments on commit d99af6c

Please sign in to comment.