Browse Source

[wip] No errors at this point

tree-traversal
Adam Cooper 8 months ago
parent
commit
e735a3eeec
  1. 1
      .gitignore
  2. 57
      src/main.rs

1
.gitignore

@ -2,3 +2,4 @@
.env
Cargo.lock
scratchpad/
*.bak

57
src/main.rs

@ -133,20 +133,7 @@ async fn traverse(mut result: Multistatus) {
let mut already_visited: bool;
// Initialize the hashmap of visited items (by etag?)
let mut visited_items = HashMap::new();
/*
match result.response[0].propstat[0].prop {
// match result.response.get(0).unwrap().propstat.get(0).unwrap().prop {
Some(prop) => match prop.get_etag {
Some(etag) => {
visited_items.insert(etag, true);
()
}
_ => current_index += 1,
},
_ => current_index += 1,
}
*/
if let Some(prop) = &result.response[0].propstat[0].prop {
if let Some(prop) = &mut result.response[0].propstat[0].prop {
if let Some(etag) = &prop.get_etag {
visited_items.insert(etag, true);
} else {
@ -157,45 +144,17 @@ async fn traverse(mut result: Multistatus) {
}
// Depth first traversal
while current_index < &result.response.len() {
match &result.response[current_index].propstat[0].prop {
while current_index < (&mut result.response).len() {
match &mut result.response[current_index].propstat[0].prop {
Some(prop) => {
match prop.get_etag {
match &prop.get_etag {
Some(etag) => {
// If result.response[current_index] has not been visited
if !visited_items.contains_key(&etag) {
// If item is a collection
match prop.resource_type {
Some(resource_type) => {
if !resource_type.collection.is_empty() {
// Get the contents XML
let folder_contents: String = get_folder_contents(
&result.response[current_index].href,
)
.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);
}
}
_ => current_index += 1,
}
}
// else
// if item is not public, publicise it.
// Add item to visited items hashmap
// Increment current_index by 1
()
}
_ => println!("something's happening"),
},
_ => println!("Something's happening.")
}
}
_ => println!("something's happening"),
},
_ => println!("Something's happening.")
}
current_index += 1;
}
}

Loading…
Cancel
Save