Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Exclude files in absolute path if they match exclude pattern (#593)
Browse files Browse the repository at this point in the history
dqkqd committed Oct 13, 2024
1 parent f567965 commit f606559
Showing 3 changed files with 30 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions selene/Cargo.toml
Original file line number Diff line number Diff line change
@@ -35,6 +35,7 @@ tracy-client = { version = "0.14.1", optional = true }
threadpool = "1.8"
toml.workspace = true
ureq = { version = "2.6.2", features = ["json"], optional = true }
pathdiff = "0.2.2"

[dev-dependencies]
pretty_assertions = "1.3"
24 changes: 22 additions & 2 deletions selene/src/main.rs
Original file line number Diff line number Diff line change
@@ -643,6 +643,26 @@ fn start(mut options: opts::Options) {

let pool = ThreadPool::new(options.num_threads);

// Directory for matching files pattern.
// If user provides a config file, we use that as our working directory, otherwise fallback to the current directory.
// The working directory needs to be an absolute path to match with paths in different directories.
let working_directory = config_directory.or_else(|| current_dir.canonicalize().ok());

let is_excluded = |path: &Path| -> bool {
if options.no_exclude {
return false;
}

// File pattern between the path we are checking and current working directory.
let file_pattern = working_directory.as_ref().and_then(|dir| {
path.canonicalize()
.ok()
.and_then(|path| pathdiff::diff_paths(path, dir))
});

file_pattern.is_some_and(|pattern| exclude_set.is_match(&pattern))
};

for filename in &options.files {
if filename == "-" {
let checker = Arc::clone(&checker);
@@ -656,7 +676,7 @@ fn start(mut options: opts::Options) {
let checker = Arc::clone(&checker);
let filename = filename.to_owned();

if !options.no_exclude && exclude_set.is_match(&filename) {
if is_excluded(Path::new(&filename)) {
continue;
}

@@ -678,7 +698,7 @@ fn start(mut options: opts::Options) {
for entry in glob {
match entry {
Ok(path) => {
if !options.no_exclude && exclude_set.is_match(&path) {
if is_excluded(&path) {
continue;
}

0 comments on commit f606559

Please sign in to comment.