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