Remove comments, stray macros, unused struct references (#7)
This commit is contained in:
parent
703a7c4810
commit
3c6afa56c4
1 changed files with 3 additions and 42 deletions
45
src/main.rs
45
src/main.rs
|
@ -1,21 +1,16 @@
|
||||||
extern crate xdg;
|
extern crate xdg;
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
use env_logger::{Env, Target};
|
use env_logger::{Env, Target};
|
||||||
#[allow(unused)]
|
use log::debug;
|
||||||
use log::{debug, error, info, log_enabled, warn};
|
|
||||||
use reqwest;
|
use reqwest;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::io::{self, Write};
|
|
||||||
#[allow(unused)]
|
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::str;
|
use std::str;
|
||||||
use toml;
|
use toml;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
#[allow(unused)]
|
use yaserde_derive::YaDeserialize;
|
||||||
use yaserde_derive::{YaDeserialize, YaSerialize};
|
|
||||||
use yaserde::de::from_str;
|
use yaserde::de::from_str;
|
||||||
|
|
||||||
#[derive(Debug, Deserialize)]
|
#[derive(Debug, Deserialize)]
|
||||||
|
@ -55,7 +50,6 @@ pub struct Multistatus {
|
||||||
#[yaserde(rename = "response", prefix = "d", namespace = "d: DAV:")]
|
#[yaserde(rename = "response", prefix = "d", namespace = "d: DAV:")]
|
||||||
pub struct NextcloudResponse {
|
pub struct NextcloudResponse {
|
||||||
#[yaserde(prefix = "d")]
|
#[yaserde(prefix = "d")]
|
||||||
// href: Option<String>,
|
|
||||||
href: String,
|
href: String,
|
||||||
#[yaserde(prefix = "d")]
|
#[yaserde(prefix = "d")]
|
||||||
propstat: Vec<Propstat>,
|
propstat: Vec<Propstat>,
|
||||||
|
@ -122,7 +116,6 @@ fn init() -> Result<Config, Box<dyn std::error::Error>> {
|
||||||
return Ok(config);
|
return Ok(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
async fn get_folder_contents(url_tail: &str, config: &Config) -> Result<String, Box<dyn std::error::Error>> {
|
async fn get_folder_contents(url_tail: &str, config: &Config) -> Result<String, Box<dyn std::error::Error>> {
|
||||||
debug!("[get_folder_contents] Entering function...");
|
debug!("[get_folder_contents] Entering function...");
|
||||||
let root_url = Url::parse(&config.paths.root)?;
|
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)
|
Ok(response_text)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
async fn publicise_it(path: &str, password: &str) -> Result<bool, Box<dyn std::error::Error>> {
|
async fn publicise_it(path: &str, password: &str) -> Result<bool, Box<dyn std::error::Error>> {
|
||||||
debug!("[publicise_it] Entering function...");
|
debug!("[publicise_it] Entering function...");
|
||||||
let url = "https://cloud.theadamcooper.com/ocs/v2.php/apps/files_sharing/api/v1/shares";
|
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)
|
Ok(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused)]
|
|
||||||
async fn traverse(mut result: Multistatus, config: &Config) -> Result<bool, Box<dyn std::error::Error>> {
|
async fn traverse(mut result: Multistatus, config: &Config) -> Result<bool, Box<dyn std::error::Error>> {
|
||||||
debug!("[traverse] Entering function...");
|
debug!("[traverse] Entering function...");
|
||||||
// Initialize the indexed "pointer"
|
|
||||||
let mut current_index: usize = 0;
|
let mut current_index: usize = 0;
|
||||||
// Initialize the hashmap of visited items (by etag?)
|
|
||||||
let mut visited_items = HashMap::new();
|
let mut visited_items = HashMap::new();
|
||||||
let href_key = (&mut result.response[current_index].href).clone();
|
let href_key = (&mut result.response[current_index].href).clone();
|
||||||
visited_items.insert(href_key, true);
|
visited_items.insert(href_key, true);
|
||||||
current_index += 1;
|
current_index += 1;
|
||||||
|
|
||||||
// Depth first traversal
|
|
||||||
while current_index < (&mut result.response).len() {
|
while current_index < (&mut result.response).len() {
|
||||||
debug!("[traverse] current_index: {:?}", current_index);
|
debug!("[traverse] current_index: {:?}", current_index);
|
||||||
debug!("[traverse] current href: {}", &result.response[current_index].href);
|
debug!("[traverse] current href: {}", &result.response[current_index].href);
|
||||||
let href_key = (&mut result.response[current_index].href).clone();
|
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) {
|
if !visited_items.contains_key(&href_key) {
|
||||||
debug!("[traverse] Fresh item...");
|
debug!("[traverse] Fresh item...");
|
||||||
// if it's a collection
|
|
||||||
if !(&mut result.response[current_index].propstat[0].prop.resource_type.collection).is_empty() {
|
if !(&mut result.response[current_index].propstat[0].prop.resource_type.collection).is_empty() {
|
||||||
debug!("[traverse] Collection...");
|
debug!("[traverse] Collection...");
|
||||||
// Get the contents XML
|
|
||||||
let folder_contents: String = get_folder_contents(
|
let folder_contents: String = get_folder_contents(
|
||||||
&result.response[current_index].href, // change to mutable borrow if necessary
|
&result.response[current_index].href,
|
||||||
config,
|
config,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
// Parse the contents XML into Multistatus
|
|
||||||
let mut new_result: Multistatus = from_str(&String::from(folder_contents)).unwrap();
|
let mut new_result: Multistatus = from_str(&String::from(folder_contents)).unwrap();
|
||||||
debug!("[traverse] Parsed:\n{:?}", new_result);
|
debug!("[traverse] Parsed:\n{:?}", new_result);
|
||||||
// Append the NextcloudResponse vector to result.response
|
|
||||||
result.response.append(&mut new_result.response);
|
result.response.append(&mut new_result.response);
|
||||||
debug!("[traverse] new vector length: {}", &result.response.len());
|
debug!("[traverse] new vector length: {}", &result.response.len());
|
||||||
} else {
|
} else {
|
||||||
debug!("[traverse] Node...");
|
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 }) {
|
if !(&mut result.response[current_index].propstat[0].prop.share_types).contains(&ShareType{ share_type: 3 }) {
|
||||||
debug!("[traverse] it's not public");
|
debug!("[traverse] it's not public");
|
||||||
// Search for username and lop.
|
|
||||||
let username = "adam";
|
let username = "adam";
|
||||||
let username_seg_string = format!("/{}/", username);
|
let username_seg_string = format!("/{}/", username);
|
||||||
let username_seg = username_seg_string.as_str();
|
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)
|
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]
|
#[tokio::main]
|
||||||
async fn main() -> std::io::Result<()> {
|
async fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue