Using href in visited_items hashmap
This commit is contained in:
parent
cb0173c440
commit
98efdaaa82
1 changed files with 8 additions and 11 deletions
19
src/main.rs
19
src/main.rs
|
@ -4,10 +4,8 @@ use env_logger::{Env, Target};
|
|||
use log::{debug, error, info, log_enabled, warn};
|
||||
use reqwest;
|
||||
use std::collections::HashMap;
|
||||
#[allow(unused)]
|
||||
use std::io::{self, BufReader, Write};
|
||||
use std::path::PathBuf;
|
||||
use url::{Url, ParseError};
|
||||
use std::io::{self, Write};
|
||||
use url::Url;
|
||||
#[allow(unused)]
|
||||
use yaserde_derive::{YaDeserialize, YaSerialize};
|
||||
use yaserde::de::from_str;
|
||||
|
@ -149,17 +147,17 @@ async fn traverse(mut result: Multistatus, password: &str) -> Result<bool, Box<d
|
|||
let mut current_index: usize = 0;
|
||||
// Initialize the hashmap of visited items (by etag?)
|
||||
let mut visited_items = HashMap::new();
|
||||
let mut etag = (&mut result.response[current_index].propstat[0].prop.get_etag).clone();
|
||||
visited_items.insert(etag, true);
|
||||
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 mut etag = (&mut result.response[current_index].propstat[0].prop.get_etag).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(&etag) {
|
||||
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() {
|
||||
|
@ -171,7 +169,6 @@ async fn traverse(mut result: Multistatus, password: &str) -> Result<bool, Box<d
|
|||
)
|
||||
.await
|
||||
.unwrap();
|
||||
// debug!("{:?}", folder_contents);
|
||||
// Parse the contents XML into Multistatus
|
||||
let mut new_result: Multistatus = from_str(&String::from(folder_contents)).unwrap();
|
||||
debug!("[traverse] Parsed:\n{:?}", new_result);
|
||||
|
@ -195,7 +192,7 @@ async fn traverse(mut result: Multistatus, password: &str) -> Result<bool, Box<d
|
|||
debug!("[traverse] it's already public");
|
||||
}
|
||||
}
|
||||
visited_items.insert(etag, true);
|
||||
visited_items.insert(href_key, true);
|
||||
debug!("[traverse] visited items: {:?}", visited_items);
|
||||
} else {
|
||||
debug!("[traverse] Already-visited item.");
|
||||
|
@ -239,7 +236,7 @@ async fn main() -> std::io::Result<()> {
|
|||
.await
|
||||
.unwrap();
|
||||
|
||||
let mut result: Multistatus = from_str(&folder_contents).unwrap();
|
||||
let result: Multistatus = from_str(&folder_contents).unwrap();
|
||||
debug!("{:?}", result);
|
||||
|
||||
let _ = traverse(result, &password).await.unwrap();
|
||||
|
|
Loading…
Reference in a new issue