From b00c30055010f23990a9887aa6894c78d2d2fd2c Mon Sep 17 00:00:00 2001 From: Mariotaku Date: Sun, 10 Nov 2024 15:40:12 +0900 Subject: [PATCH] improved path excluding --- ares-package/src/input/data.rs | 2 +- ares-package/src/input/mod.rs | 17 ++++++++++++++--- ares-package/src/packaging/data.rs | 2 +- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/ares-package/src/input/data.rs b/ares-package/src/input/data.rs index 6c87dad..dfc2896 100644 --- a/ares-package/src/input/data.rs +++ b/ares-package/src/input/data.rs @@ -53,7 +53,7 @@ impl DataInfo { } let mut excludes: Option = None; if !exclude_queries.is_empty() { - excludes = Regex::new(&format!("(?i){}", exclude_queries.join("|"))).ok(); + excludes = Some(Regex::new(&format!("(?i){}", exclude_queries.join("|"))).unwrap()); } for service_dir in service_dirs { let service_dir = service_dir.as_ref(); diff --git a/ares-package/src/input/mod.rs b/ares-package/src/input/mod.rs index d423265..4e3dbcb 100644 --- a/ares-package/src/input/mod.rs +++ b/ares-package/src/input/mod.rs @@ -10,9 +10,20 @@ pub mod data; pub mod service; pub mod validation; -pub(crate) fn filter_by_excludes(entry: &DirEntry, excludes: Option<&Regex>) -> bool { +pub(crate) fn filter_by_excludes>( + base: P, + entry: &DirEntry, + excludes: Option<&Regex>, +) -> bool { if let Some(exclude) = excludes { - return !exclude.is_match(entry.path().to_slash_lossy().as_ref()); + return !exclude.is_match( + entry + .path() + .strip_prefix(base) + .unwrap() + .to_slash_lossy() + .as_ref(), + ); } true } @@ -22,7 +33,7 @@ pub(crate) fn dir_size>(path: P, excludes: Option<&Regex>) -> Res let mut size = 0; for entry in walker .into_iter() - .filter_entry(|entry| filter_by_excludes(entry, excludes)) + .filter_entry(|entry| filter_by_excludes(&path, entry, excludes)) { let entry = entry?; size += entry.metadata()?.len(); diff --git a/ares-package/src/packaging/data.rs b/ares-package/src/packaging/data.rs index 54224c9..2ff68b2 100644 --- a/ares-package/src/packaging/data.rs +++ b/ares-package/src/packaging/data.rs @@ -135,7 +135,7 @@ where .sort_by_file_name(); for entry in walker .into_iter() - .filter_entry(|entry| filter_by_excludes(entry, excludes)) + .filter_entry(|entry| filter_by_excludes(base_path, entry, excludes)) { let entry = entry?; let entry_type = entry.file_type();