Skip to content

Commit

Permalink
improved path excluding
Browse files Browse the repository at this point in the history
  • Loading branch information
mariotaku committed Nov 10, 2024
1 parent 854ef14 commit b00c300
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion ares-package/src/input/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ impl DataInfo {
}
let mut excludes: Option<Regex> = 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();
Expand Down
17 changes: 14 additions & 3 deletions ares-package/src/input/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<P: AsRef<Path>>(
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
}
Expand All @@ -22,7 +33,7 @@ pub(crate) fn dir_size<P: AsRef<Path>>(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();
Expand Down
2 changes: 1 addition & 1 deletion ares-package/src/packaging/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit b00c300

Please sign in to comment.