diff --git a/src/list.rs b/src/list.rs index ab972fb..0d52f1a 100644 --- a/src/list.rs +++ b/src/list.rs @@ -17,15 +17,17 @@ pub struct List { impl List { pub async fn from_opt(list: &Vec, cache: Option) -> Result { - fn handle(this: &mut HashSet, line: &str) { + fn handle(this: &mut HashSet, line: &str) -> Option { if line.starts_with("/") || line.starts_with("#") || line.is_empty() { - return; - } - if !this.insert(Item::from_line(line)) { - warn!("Duplicated list record: `{line}`") + return None; } + Some(this.insert(Item::from_line(line))) } + let mut index = HashSet::new(); + + let mut list_rules_total = 0; + for i in list { for line in if i.contains("://") { let response = reqwest::get(i).await?; @@ -41,18 +43,31 @@ impl List { } .lines() { - handle(&mut index, line) + if handle(&mut index, line).is_some_and(|status| !status) { + warn!("List `{i}` contains duplicated entry: `{line}`") + } + list_rules_total += 1 } } let cache = Cache::from_path(cache).await?; - if let Some(data) = cache.read().await? { - for line in data.lines() { - handle(&mut index, line) - } - } - info!("Total list entries parsed: {}", index.len()); + let cache_rules_total = cache.read().await?.map(|data| { + let mut t = 0; + for line in data.lines() { + if handle(&mut index, line).is_some_and(|status| !status) { + warn!("Cache file contains duplicated entry: `{line}`") + } + t += 1 + } + t + }); + + let len = index.len(); + info!( + "Total rules parsed: {len} (lists: {list_rules_total} / cache: {cache_rules_total:?})", + ); + Ok(Self { index: RwLock::new(index), cache,