[wip] Starting depth-first tree traversal
This commit is contained in:
parent
5bc4b24fd9
commit
d00bc97478
3 changed files with 65 additions and 8 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
@ -11,6 +11,12 @@ dependencies = [
|
||||||
"memchr",
|
"memchr",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "array_tool"
|
||||||
|
version = "1.0.3"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "8f8cb5d814eb646a863c4f24978cff2880c4be96ad8cde2c0f0678732902e271"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "atty"
|
name = "atty"
|
||||||
version = "0.2.14"
|
version = "0.2.14"
|
||||||
|
@ -574,6 +580,7 @@ dependencies = [
|
||||||
name = "publicise-rs"
|
name = "publicise-rs"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"array_tool",
|
||||||
"dotenv",
|
"dotenv",
|
||||||
"env_logger",
|
"env_logger",
|
||||||
"log",
|
"log",
|
||||||
|
|
|
@ -6,6 +6,7 @@ edition = "2021"
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
array_tool = "1.0.3"
|
||||||
dotenv = "0.15.0"
|
dotenv = "0.15.0"
|
||||||
env_logger = "0.8.4"
|
env_logger = "0.8.4"
|
||||||
log = "0.4.0"
|
log = "0.4.0"
|
||||||
|
|
65
src/main.rs
65
src/main.rs
|
@ -5,8 +5,11 @@ use log::{debug, error, info, log_enabled, warn};
|
||||||
use reqwest;
|
use reqwest;
|
||||||
#[allow(unused)]
|
#[allow(unused)]
|
||||||
use std::io::{self, BufReader, Write};
|
use std::io::{self, BufReader, Write};
|
||||||
|
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() {}
|
||||||
|
@ -83,11 +86,10 @@ pub struct Collection {
|
||||||
collection: Option<String>,
|
collection: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_folder_contents(
|
async fn get_folder_contents(url_tail: &str) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
password: String,
|
|
||||||
url_tail: &str,
|
|
||||||
) -> Result<String, Box<dyn std::error::Error>> {
|
|
||||||
debug!("Entering: get_folder_contents()");
|
debug!("Entering: get_folder_contents()");
|
||||||
|
let password = get_password().unwrap().trim().to_string();
|
||||||
|
debug!("Received password: {}[END]", password);
|
||||||
let root_url = "https://theadamcooper.com";
|
let root_url = "https://theadamcooper.com";
|
||||||
let method = reqwest::Method::from_bytes(b"PROPFIND").unwrap();
|
let method = reqwest::Method::from_bytes(b"PROPFIND").unwrap();
|
||||||
let client = reqwest::Client::new();
|
let client = reqwest::Client::new();
|
||||||
|
@ -119,6 +121,53 @@ async fn get_folder_contents(
|
||||||
Ok(response_text)
|
Ok(response_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn traverse(queue: Vec<NextcloudResponse>) {
|
||||||
|
debug!("Entering: traverse()");
|
||||||
|
// Initialize the indexed "pointer"
|
||||||
|
let 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);
|
||||||
|
()
|
||||||
|
},
|
||||||
|
_ => println!("something's happening"),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
_ => println!("something's happening"),
|
||||||
|
}
|
||||||
|
// Depth first traversal
|
||||||
|
while !queue.is_empty() {
|
||||||
|
match &queue[current_index].propstat[0].prop {
|
||||||
|
Some(prop) => {
|
||||||
|
match &prop.get_etag {
|
||||||
|
Some(etag) => {
|
||||||
|
// If queue[current_index] has not been visited
|
||||||
|
if !visited_items.contains_key(etag) {
|
||||||
|
// If item is a collection
|
||||||
|
|
||||||
|
// Get the contents XML
|
||||||
|
// Parse the contents XML into Multistatus
|
||||||
|
// Append the NextcloudResponse vector to queue
|
||||||
|
}
|
||||||
|
// 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"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn get_password() -> Result<String, std::io::Error> {
|
fn get_password() -> Result<String, std::io::Error> {
|
||||||
print!("Nextcloud password: ");
|
print!("Nextcloud password: ");
|
||||||
io::stdout().flush().unwrap();
|
io::stdout().flush().unwrap();
|
||||||
|
@ -146,16 +195,16 @@ async fn main() -> std::io::Result<()> {
|
||||||
.target(Target::Stdout)
|
.target(Target::Stdout)
|
||||||
.init();
|
.init();
|
||||||
println!("Publicise it!");
|
println!("Publicise it!");
|
||||||
let password = get_password().unwrap().trim().to_string();
|
|
||||||
debug!("Received password: {}[END]", password);
|
|
||||||
|
|
||||||
let folder_contents =
|
let folder_contents: String =
|
||||||
get_folder_contents(password, "/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")
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
debug!("{:?}", folder_contents);
|
debug!("{:?}", folder_contents);
|
||||||
|
|
||||||
let result: Multistatus = from_str(&folder_contents).unwrap();
|
let result: Multistatus = from_str(&folder_contents).unwrap();
|
||||||
println!("{:?}", result);
|
println!("{:?}", result);
|
||||||
|
|
||||||
|
// traverse(result.response);
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue