[wip] Still no errors

This commit is contained in:
Adam Cooper 2022-02-20 01:25:34 -05:00
parent ebc6eaf6ee
commit b331363d09
1 changed files with 29 additions and 33 deletions

View File

@ -41,9 +41,9 @@ pub struct NextcloudResponse {
#[yaserde(rename = "propstat", prefix = "d", namespace = "d: DAV:")]
pub struct Propstat {
#[yaserde(prefix = "d")]
prop: Option<Prop>,
prop: Prop,
#[yaserde(prefix = "d")]
status: Option<String>,
status: String,
}
#[derive(Default, PartialEq, Debug, YaDeserialize)]
@ -54,17 +54,17 @@ pub struct Propstat {
)]
pub struct Prop {
#[yaserde(prefix = "d", rename = "getlastmodified")]
get_last_modified: Option<String>,
get_last_modified: String,
#[yaserde(prefix = "oc")]
permissions: Option<String>,
permissions: String,
#[yaserde(prefix = "d", rename = "resourcetype")]
resource_type: Option<ResourceType>,
resource_type: ResourceType,
#[yaserde(prefix = "d", rename = "getetag")]
get_etag: Option<String>,
get_etag: String,
#[yaserde(prefix = "d", rename = "getcontentlength")]
get_content_length: Option<u32>,
get_content_length: u32,
#[yaserde(prefix = "d", rename = "getcontenttype")]
get_content_type: Option<String>,
get_content_type: String,
#[yaserde(prefix = "oc", rename = "share-types")]
share_types: Vec<ShareType>,
}
@ -87,7 +87,7 @@ pub struct ResourceType {
#[yaserde(rename = "collection", namespace = "d: DAV:")]
pub struct Collection {
#[yaserde(prefix = "d")]
collection: Option<String>,
collection: String,
}
async fn get_folder_contents(url_tail: &String) -> Result<String, Box<dyn std::error::Error>> {
@ -130,36 +130,32 @@ async fn traverse(mut result: Multistatus) {
debug!("Entering: traverse()");
// Initialize the indexed "pointer"
let mut current_index: usize = 0;
let mut already_visited: bool;
// Initialize the hashmap of visited items (by etag?)
let mut visited_items = HashMap::new();
if let Some(prop) = &mut result.response[0].propstat[0].prop {
if let Some(etag) = &prop.get_etag {
visited_items.insert(etag, true);
} else {
current_index += 1;
}
} else {
current_index += 1;
}
let mut etag = (&mut result.response[current_index].propstat[0].prop.get_etag).clone();
visited_items.insert(etag, true);
current_index += 1;
// Depth first traversal
while current_index < (&mut result.response).len() {
match &mut result.response[current_index].propstat[0].prop {
Some(prop) => {
match &prop.get_etag {
Some(etag) => {
// 2022-02-17 When I tried to add the next bit here,
// the borrow checker objected to mutable borrows in
// lines 136 and 147.
// As a result, I should try to get this working
// without `Option<T>` first.
},
_ => println!("Something's happening.")
}
},
_ => println!("Something's happening.")
// If result.response[current_index] has not been visited
if !visited_items.contains_key(&mut result.response[current_index].propstat[0].prop.get_etag) {
if !(&mut result.response[current_index].propstat[0].prop.resource_type.collection).is_empty() {
// Get the contents XML
let folder_contents: String = get_folder_contents(
&result.response[current_index].href, // change to mutable borrow if necessary
)
.await
.unwrap();
debug!("{:?}", folder_contents);
// Parse the contents XML into Multistatus
let mut new_result: Multistatus = from_str(&String::from(folder_contents)).unwrap();
// Append the NextcloudResponse vector to result.response
result.response.append(&mut new_result.response);
} // else if it's not public, publicise it.
// also add debugging statements in this function throughout!
}
current_index += 1;
}
}