Remove comments, stray macros, unused struct references (#7)

This commit is contained in:
Adam Cooper 2022-03-21 03:08:08 -04:00
parent 703a7c4810
commit 3c6afa56c4

View file

@ -1,21 +1,16 @@
extern crate xdg;
#[allow(unused)]
use env_logger::{Env, Target};
#[allow(unused)]
use log::{debug, error, info, log_enabled, warn};
use log::debug;
use reqwest;
use serde::Deserialize;
use std::collections::HashMap;
use std::fs;
use std::io::{self, Write};
#[allow(unused)]
use std::process::Command;
use std::str;
use toml;
use url::Url;
#[allow(unused)]
use yaserde_derive::{YaDeserialize, YaSerialize};
use yaserde_derive::YaDeserialize;
use yaserde::de::from_str;
#[derive(Debug, Deserialize)]
@ -55,7 +50,6 @@ pub struct Multistatus {
#[yaserde(rename = "response", prefix = "d", namespace = "d: DAV:")]
pub struct NextcloudResponse {
#[yaserde(prefix = "d")]
// href: Option<String>,
href: String,
#[yaserde(prefix = "d")]
propstat: Vec<Propstat>,
@ -122,7 +116,6 @@ fn init() -> Result<Config, Box<dyn std::error::Error>> {
return Ok(config);
}
#[allow(unused)]
async fn get_folder_contents(url_tail: &str, config: &Config) -> Result<String, Box<dyn std::error::Error>> {
debug!("[get_folder_contents] Entering function...");
let root_url = Url::parse(&config.paths.root)?;
@ -156,7 +149,6 @@ async fn get_folder_contents(url_tail: &str, config: &Config) -> Result<String,
Ok(response_text)
}
#[allow(unused)]
async fn publicise_it(path: &str, password: &str) -> Result<bool, Box<dyn std::error::Error>> {
debug!("[publicise_it] Entering function...");
let url = "https://cloud.theadamcooper.com/ocs/v2.php/apps/files_sharing/api/v1/shares";
@ -178,47 +170,36 @@ async fn publicise_it(path: &str, password: &str) -> Result<bool, Box<dyn std::e
Ok(true)
}
#[allow(unused)]
async fn traverse(mut result: Multistatus, config: &Config) -> Result<bool, Box<dyn std::error::Error>> {
debug!("[traverse] Entering function...");
// Initialize the indexed "pointer"
let mut current_index: usize = 0;
// Initialize the hashmap of visited items (by etag?)
let mut visited_items = HashMap::new();
let href_key = (&mut result.response[current_index].href).clone();
visited_items.insert(href_key, true);
current_index += 1;
// Depth first traversal
while current_index < (&mut result.response).len() {
debug!("[traverse] current_index: {:?}", current_index);
debug!("[traverse] current href: {}", &result.response[current_index].href);
let href_key = (&mut result.response[current_index].href).clone();
// If result.response[current_index] has not been visited
if !visited_items.contains_key(&href_key) {
debug!("[traverse] Fresh item...");
// if it's a collection
if !(&mut result.response[current_index].propstat[0].prop.resource_type.collection).is_empty() {
debug!("[traverse] Collection...");
// Get the contents XML
let folder_contents: String = get_folder_contents(
&result.response[current_index].href, // change to mutable borrow if necessary
&result.response[current_index].href,
config,
)
.await
.unwrap();
// Parse the contents XML into Multistatus
let mut new_result: Multistatus = from_str(&String::from(folder_contents)).unwrap();
debug!("[traverse] Parsed:\n{:?}", new_result);
// Append the NextcloudResponse vector to result.response
result.response.append(&mut new_result.response);
debug!("[traverse] new vector length: {}", &result.response.len());
} else {
debug!("[traverse] Node...");
// else it's a node. if it's not public, publicise it.
if !(&mut result.response[current_index].propstat[0].prop.share_types).contains(&ShareType{ share_type: 3 }) {
debug!("[traverse] it's not public");
// Search for username and lop.
let username = "adam";
let username_seg_string = format!("/{}/", username);
let username_seg = username_seg_string.as_str();
@ -240,26 +221,6 @@ async fn traverse(mut result: Multistatus, config: &Config) -> Result<bool, Box<
Ok(true)
}
#[allow(unused)]
fn get_password() -> Result<String, std::io::Error> {
print!("Nextcloud password: ");
io::stdout().flush().unwrap();
let mut buffer = String::new();
let stdin = io::stdin();
match stdin.read_line(&mut buffer) {
Ok(_) => Ok(buffer),
Err(error) => Err(error),
}
}
#[allow(unused)]
fn indent(size: usize) -> String {
const INDENT: &'static str = " ";
(0..size)
.map(|_| INDENT)
.fold(String::with_capacity(size * INDENT.len()), |r, s| r + s)
}
#[tokio::main]
async fn main() -> std::io::Result<()> {