[wip] Change of approach: moving the Multistatus

Move the Multistatus value from the main function into the traverse
function, as it will not be used in the main function afterwards.
In the traverse function, the struct is now borrowed as mutable,
which fixes the append function, but we'll probably need to use
references in all the match arms.
This commit is contained in:
Adam Cooper 2022-02-15 09:31:15 -05:00
parent 1c8e868afd
commit 06e60dce14
1 changed files with 7 additions and 9 deletions

View File

@ -126,7 +126,7 @@ async fn get_folder_contents(url_tail: &String) -> Result<String, Box<dyn std::e
} }
#[tokio::main] #[tokio::main]
async fn traverse(result: &Multistatus) { 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;
@ -134,7 +134,7 @@ async fn traverse(result: &Multistatus) {
// 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();
// match result.response[0].propstat[0].prop { // match result.response[0].propstat[0].prop {
match result.response.into_iter().nth(0).unwrap() match &result.response.into_iter().nth(0).unwrap()
.propstat.into_iter().nth(0).unwrap().prop { .propstat.into_iter().nth(0).unwrap().prop {
Some(prop) => match prop.get_etag { Some(prop) => match prop.get_etag {
Some(etag) => { Some(etag) => {
@ -149,14 +149,12 @@ async fn traverse(result: &Multistatus) {
while !result.response.is_empty() { while !result.response.is_empty() {
match &result.response[current_index].propstat[0].prop { match &result.response[current_index].propstat[0].prop {
Some(prop) => { Some(prop) => {
match &prop.get_etag { match prop.get_etag {
Some(etag) => { Some(etag) => {
// If result.response[current_index] has not been visited // If result.response[current_index] has not been visited
if !visited_items.contains_key(etag) { if !visited_items.contains_key(&etag) {
// If item is a collection // If item is a collection
// TODO(amcooper): Again, replace unwrap with the match implementation, match prop.resource_type {
// or find another way to handle these structures.
match &prop.resource_type {
Some(resource_type) => { Some(resource_type) => {
if !resource_type.collection.is_empty() { if !resource_type.collection.is_empty() {
// Get the contents XML // Get the contents XML
@ -169,7 +167,7 @@ async fn traverse(result: &Multistatus) {
// Parse the contents XML into Multistatus // Parse the contents XML into Multistatus
let mut new_result: Multistatus = from_str(&String::from(folder_contents)).unwrap(); let mut new_result: Multistatus = from_str(&String::from(folder_contents)).unwrap();
// Append the NextcloudResponse vector to result.response // Append the NextcloudResponse vector to result.response
result.response.append(&new_result.response); result.response.append(&mut new_result.response);
} }
} }
_ => current_index += 1, _ => current_index += 1,
@ -228,6 +226,6 @@ async fn main() -> std::io::Result<()> {
let mut result: Multistatus = from_str(&folder_contents).unwrap(); let mut result: Multistatus = from_str(&folder_contents).unwrap();
println!("{:?}", result); println!("{:?}", result);
traverse(&result); traverse(result);
Ok(()) Ok(())
} }