diff --git a/src/main.rs b/src/main.rs index 0676c84..4e18b6b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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, #[yaserde(prefix = "d")] - status: Option, + 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, + get_last_modified: String, #[yaserde(prefix = "oc")] - permissions: Option, + permissions: String, #[yaserde(prefix = "d", rename = "resourcetype")] - resource_type: Option, + resource_type: ResourceType, #[yaserde(prefix = "d", rename = "getetag")] - get_etag: Option, + get_etag: String, #[yaserde(prefix = "d", rename = "getcontentlength")] - get_content_length: Option, + get_content_length: u32, #[yaserde(prefix = "d", rename = "getcontenttype")] - get_content_type: Option, + get_content_type: String, #[yaserde(prefix = "oc", rename = "share-types")] share_types: Vec, } @@ -87,7 +87,7 @@ pub struct ResourceType { #[yaserde(rename = "collection", namespace = "d: DAV:")] pub struct Collection { #[yaserde(prefix = "d")] - collection: Option, + collection: String, } async fn get_folder_contents(url_tail: &String) -> Result> { @@ -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` 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; } }