[wip] Commit before string refactor

This commit is contained in:
Adam Cooper 2022-01-24 08:58:15 -05:00
parent e034933fc0
commit 767d77ffcc
2 changed files with 24 additions and 18 deletions

2
.gitignore vendored
View file

@ -1,4 +1,4 @@
/target /target
.env .env
Cargo.lock Cargo.lock
example*.xml scratchpad/

View file

@ -8,8 +8,6 @@ use std::io::{self, BufReader, Write};
use std::collections::HashMap; use std::collections::HashMap;
#[allow(unused)] #[allow(unused)]
use yaserde_derive::{YaDeserialize, YaSerialize}; use yaserde_derive::{YaDeserialize, YaSerialize};
#[allow(unused)]
use array_tool::vec::Shift;
#[allow(unused)] #[allow(unused)]
fn publicise() {} fn publicise() {}
@ -121,7 +119,8 @@ async fn get_folder_contents(url_tail: &str) -> Result<String, Box<dyn std::erro
Ok(response_text) Ok(response_text)
} }
fn traverse(queue: Vec<NextcloudResponse>) { #[tokio::main]
async fn traverse(queue: Vec<NextcloudResponse>) {
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;
@ -131,20 +130,11 @@ fn traverse(queue: Vec<NextcloudResponse>) {
match &queue[0].propstat[0].prop { match &queue[0].propstat[0].prop {
Some(prop) => { Some(prop) => {
match &prop.get_etag { match &prop.get_etag {
Some(etag) => { Some(etag) => { visited_items.insert(etag, true); () },
visited_items.insert(etag, true); _ => current_index += 1
()
},
_ => {
current_index += 1;
()
}
} }
}, },
_ => { _ => current_index += 1
current_index +=1;
()
}
} }
// Depth first traversal // Depth first traversal
while !queue.is_empty() { while !queue.is_empty() {
@ -155,11 +145,26 @@ fn traverse(queue: Vec<NextcloudResponse>) {
// If queue[current_index] has not been visited // If queue[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,
// 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 // 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 // Parse the contents XML into Multistatus
// Append the NextcloudResponse vector to queue // Append the NextcloudResponse vector to queue
} }
},
_ => current_index += 1
}
}
// else // else
// if item is not public, publicise it. // if item is not public, publicise it.
// Add item to visited items hashmap // Add item to visited items hashmap
@ -204,7 +209,8 @@ async fn main() -> std::io::Result<()> {
println!("Publicise it!"); println!("Publicise it!");
let folder_contents: String = 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 .await
.unwrap(); .unwrap();
debug!("{:?}", folder_contents); debug!("{:?}", folder_contents);