[wip] Commit before appeasing the borrow checker
To appease the borrow checker, we'll move the whole struct from main() into tree_traversal().
This commit is contained in:
parent
767d77ffcc
commit
3b69ca58cd
1 changed files with 50 additions and 40 deletions
90
src/main.rs
90
src/main.rs
|
@ -3,11 +3,12 @@ use env_logger::{Env, Target};
|
|||
#[allow(unused)]
|
||||
use log::{debug, error, info, log_enabled, warn};
|
||||
use reqwest;
|
||||
#[allow(unused)]
|
||||
use std::io::{self, BufReader, Write};
|
||||
use std::collections::HashMap;
|
||||
#[allow(unused)]
|
||||
use std::io::{self, BufReader, Write};
|
||||
#[allow(unused)]
|
||||
use yaserde_derive::{YaDeserialize, YaSerialize};
|
||||
use yaserde::de::from_str;
|
||||
|
||||
#[allow(unused)]
|
||||
fn publicise() {}
|
||||
|
@ -19,7 +20,7 @@ fn publicise() {}
|
|||
namespace = "d: DAV:",
|
||||
namespace = "nc: http://nextcloud.org/ns",
|
||||
namespace = "oc: http://owncloud.org/ns",
|
||||
namespace = "s: http://sabredav.org/ns",
|
||||
namespace = "s: http://sabredav.org/ns"
|
||||
)]
|
||||
pub struct Multistatus {
|
||||
#[yaserde(prefix = "d")]
|
||||
|
@ -30,7 +31,8 @@ pub struct Multistatus {
|
|||
#[yaserde(rename = "response", prefix = "d", namespace = "d: DAV:")]
|
||||
pub struct NextcloudResponse {
|
||||
#[yaserde(prefix = "d")]
|
||||
href: Option<String>,
|
||||
// href: Option<String>,
|
||||
href: String,
|
||||
#[yaserde(prefix = "d")]
|
||||
propstat: Vec<Propstat>,
|
||||
}
|
||||
|
@ -45,7 +47,11 @@ pub struct Propstat {
|
|||
}
|
||||
|
||||
#[derive(Default, PartialEq, Debug, YaDeserialize)]
|
||||
#[yaserde(rename = "prop", namespace = "d: DAV:", namespace = "oc: http://owncloud.org/ns")]
|
||||
#[yaserde(
|
||||
rename = "prop",
|
||||
namespace = "d: DAV:",
|
||||
namespace = "oc: http://owncloud.org/ns"
|
||||
)]
|
||||
pub struct Prop {
|
||||
#[yaserde(prefix = "d", rename = "getlastmodified")]
|
||||
get_last_modified: Option<String>,
|
||||
|
@ -84,7 +90,7 @@ pub struct Collection {
|
|||
collection: Option<String>,
|
||||
}
|
||||
|
||||
async fn get_folder_contents(url_tail: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||
async fn get_folder_contents(url_tail: &String) -> Result<String, Box<dyn std::error::Error>> {
|
||||
debug!("Entering: get_folder_contents()");
|
||||
let password = get_password().unwrap().trim().to_string();
|
||||
debug!("Received password: {}[END]", password);
|
||||
|
@ -120,21 +126,24 @@ async fn get_folder_contents(url_tail: &str) -> Result<String, Box<dyn std::erro
|
|||
}
|
||||
|
||||
#[tokio::main]
|
||||
async fn traverse(queue: Vec<NextcloudResponse>) {
|
||||
async fn traverse(mut queue: Vec<NextcloudResponse>) {
|
||||
debug!("Entering: traverse()");
|
||||
// Initialize the indexed "pointer"
|
||||
let mut current_index: usize = 0;
|
||||
let mut already_visited: bool;
|
||||
// Initialize the hashmap of visited items (by etag?)
|
||||
let mut visited_items = HashMap::new();
|
||||
match &queue[0].propstat[0].prop {
|
||||
Some(prop) => {
|
||||
match &prop.get_etag {
|
||||
Some(etag) => { visited_items.insert(etag, true); () },
|
||||
_ => current_index += 1
|
||||
// match queue[0].propstat[0].prop {
|
||||
match queue.into_iter().nth(0).unwrap()
|
||||
.propstat.into_iter().nth(0).unwrap().prop {
|
||||
Some(prop) => match &prop.get_etag {
|
||||
Some(etag) => {
|
||||
visited_items.insert(etag, true);
|
||||
()
|
||||
}
|
||||
_ => current_index += 1,
|
||||
},
|
||||
_ => current_index += 1
|
||||
_ => current_index += 1,
|
||||
}
|
||||
// Depth first traversal
|
||||
while !queue.is_empty() {
|
||||
|
@ -142,38 +151,39 @@ async fn traverse(queue: Vec<NextcloudResponse>) {
|
|||
Some(prop) => {
|
||||
match &prop.get_etag {
|
||||
Some(etag) => {
|
||||
// If queue[current_index] has not been visited
|
||||
// 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())
|
||||
// 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
|
||||
let folder_contents: String = get_folder_contents(
|
||||
&queue[current_index].href,
|
||||
)
|
||||
.await
|
||||
.unwrap();
|
||||
debug!("{:?}", folder_contents);
|
||||
*/
|
||||
// Parse the contents XML into Multistatus
|
||||
// Append the NextcloudResponse vector to queue
|
||||
}
|
||||
},
|
||||
_ => current_index += 1
|
||||
debug!("{:?}", folder_contents);
|
||||
// Parse the contents XML into Multistatus
|
||||
let mut result: Multistatus = from_str(&String::from(folder_contents)).unwrap();
|
||||
// Append the NextcloudResponse vector to queue
|
||||
queue.append(&mut result.response);
|
||||
}
|
||||
}
|
||||
_ => current_index += 1,
|
||||
}
|
||||
}
|
||||
// else
|
||||
// if item is not public, publicise it.
|
||||
// Add item to visited items hashmap
|
||||
// Increment current_index by 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"),
|
||||
}
|
||||
current_index += 1;
|
||||
|
@ -201,7 +211,7 @@ fn indent(size: usize) -> String {
|
|||
|
||||
#[tokio::main]
|
||||
async fn main() -> std::io::Result<()> {
|
||||
use yaserde::de::from_str;
|
||||
// use yaserde::de::from_str;
|
||||
|
||||
env_logger::Builder::from_env(Env::default().default_filter_or("trace"))
|
||||
.target(Target::Stdout)
|
||||
|
@ -210,12 +220,12 @@ async fn main() -> std::io::Result<()> {
|
|||
|
||||
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")
|
||||
get_folder_contents(&String::from("/nextcloud/remote.php/dav/files/adam/test_public"))
|
||||
.await
|
||||
.unwrap();
|
||||
debug!("{:?}", folder_contents);
|
||||
|
||||
let result: Multistatus = from_str(&folder_contents).unwrap();
|
||||
let mut result: Multistatus = from_str(&folder_contents).unwrap();
|
||||
println!("{:?}", result);
|
||||
|
||||
// traverse(result.response);
|
||||
|
|
Loading…
Reference in a new issue