From 767d77ffcc0f6c62f953979a6b735776c170a6bf Mon Sep 17 00:00:00 2001 From: Adam Cooper Date: Mon, 24 Jan 2022 08:58:15 -0500 Subject: [PATCH] [wip] Commit before string refactor --- .gitignore | 2 +- src/main.rs | 40 +++++++++++++++++++++++----------------- 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/.gitignore b/.gitignore index 9afe259..02746a8 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ /target .env Cargo.lock -example*.xml +scratchpad/ diff --git a/src/main.rs b/src/main.rs index 156eb99..090f724 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,8 +8,6 @@ use std::io::{self, BufReader, Write}; use std::collections::HashMap; #[allow(unused)] use yaserde_derive::{YaDeserialize, YaSerialize}; -#[allow(unused)] -use array_tool::vec::Shift; #[allow(unused)] fn publicise() {} @@ -121,7 +119,8 @@ async fn get_folder_contents(url_tail: &str) -> Result) { +#[tokio::main] +async fn traverse(queue: Vec) { debug!("Entering: traverse()"); // Initialize the indexed "pointer" let mut current_index: usize = 0; @@ -131,20 +130,11 @@ fn traverse(queue: Vec) { match &queue[0].propstat[0].prop { Some(prop) => { match &prop.get_etag { - Some(etag) => { - visited_items.insert(etag, true); - () - }, - _ => { - current_index += 1; - () - } + Some(etag) => { visited_items.insert(etag, true); () }, + _ => current_index += 1 } }, - _ => { - current_index +=1; - () - } + _ => current_index += 1 } // Depth first traversal while !queue.is_empty() { @@ -155,10 +145,25 @@ fn traverse(queue: Vec) { // If queue[current_index] has not been visited if !visited_items.contains_key(etag) { // If item is a collection - + // TODO(amcooper): Again, replace unwrap with the match implementation, + // or find another way to handle these structures. + match &prop.resource_type { + Some(resource_type) => { + if !resource_type.collection.is_empty() { // Get the contents XML + /* TODO(amcooper): Fix argument + let folder_contents: String = + get_folder_contents(&queue[current_index].href.unwrap()) + .await + .unwrap(); + debug!("{:?}", folder_contents); + */ // Parse the contents XML into Multistatus // Append the NextcloudResponse vector to queue + } + }, + _ => current_index += 1 + } } // else // if item is not public, publicise it. @@ -204,7 +209,8 @@ async fn main() -> std::io::Result<()> { println!("Publicise it!"); let folder_contents: String = - get_folder_contents("/nextcloud/remote.php/dav/files/adam/test_public/2019_test_public") + // get_folder_contents("/nextcloud/remote.php/dav/files/adam/test_public/2019_test_public") + get_folder_contents("/nextcloud/remote.php/dav/files/adam/test_public") .await .unwrap(); debug!("{:?}", folder_contents);