Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use globset instead of glob #156

Merged
merged 2 commits into from Nov 21, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ Compress each file when embedding into the binary. Compression is done via [`inc

### `include-exclude`
Filter files to be embedded with multiple `#[include = "*.txt"]` and `#[exclude = "*.jpg"]` attributes.
Matching is done on relative file paths, via [`glob`].
Matching is done on relative file paths, via [`globset`].
`exclude` attributes have higher priority than `include` attributes.
Example:

Expand Down Expand Up @@ -177,4 +177,4 @@ Go Rusketeers!
The power is yours!

[`include-flate`]: https://crates.io/crates/include-flate
[`glob`]: https://crates.io/crates/glob
[`globset`]: https://crates.io/crates/globset
6 changes: 3 additions & 3 deletions utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ edition = "2018"
walkdir = "2.3.1"
sha2 = "0.9"

[dependencies.glob]
version = "0.3.0"
[dependencies.globset]
version = "0.4.8"
optional = true

[features]
debug-embed = []
include-exclude = ["glob"]
include-exclude = ["globset"]
14 changes: 9 additions & 5 deletions utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ pub fn is_path_included(_path: &str, _includes: &[&str], _excludes: &[&str]) ->

#[cfg(feature = "include-exclude")]
pub fn is_path_included(rel_path: &str, includes: &[&str], excludes: &[&str]) -> bool {
use glob::Pattern;
use globset::Glob;

// ignore path matched by exclusion pattern
for exclude in excludes {
let pattern = Pattern::new(exclude).unwrap_or_else(|_| panic!("invalid exclude pattern '{}'", exclude));
let pattern = Glob::new(exclude)
.unwrap_or_else(|_| panic!("invalid exclude pattern '{}'", exclude))
.compile_matcher();

if pattern.matches(rel_path) {
if pattern.is_match(rel_path) {
return false;
}
}
Expand All @@ -37,9 +39,11 @@ pub fn is_path_included(rel_path: &str, includes: &[&str], excludes: &[&str]) ->

// accept path if matched by inclusion pattern
for include in includes {
let pattern = Pattern::new(include).unwrap_or_else(|_| panic!("invalid include pattern '{}'", include));
let pattern = Glob::new(include)
.unwrap_or_else(|_| panic!("invalid include pattern '{}'", include))
.compile_matcher();

if pattern.matches(rel_path) {
if pattern.is_match(rel_path) {
return true;
}
}
Expand Down