-
-
Notifications
You must be signed in to change notification settings - Fork 77
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
Fix: Exclude not working with absolute path in some cases (#593) #618
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -512,6 +512,7 @@ fn start(mut options: opts::Options) { | |||||||
|
||||||||
let (config, config_directory): (CheckerConfig<toml::value::Value>, Option<PathBuf>) = | ||||||||
match options.config { | ||||||||
// User provides a config file. We must read it and report if it is misconfigured. | ||||||||
Some(config_file) => { | ||||||||
let config_contents = match fs::read_to_string(&config_file) { | ||||||||
Ok(contents) => contents, | ||||||||
|
@@ -522,10 +523,16 @@ fn start(mut options: opts::Options) { | |||||||
}; | ||||||||
|
||||||||
match toml::from_str(&config_contents) { | ||||||||
Ok(config) => ( | ||||||||
config, | ||||||||
Path::new(&config_file).parent().map(Path::to_path_buf), | ||||||||
), | ||||||||
Ok(config) => { | ||||||||
// Get config directory to using absolute path. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
// There is case where `config = Some("selene.toml")`, | ||||||||
// which returns `""`` when getting parent directory. | ||||||||
Comment on lines
+528
to
+529
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does this mean? |
||||||||
let config_directory = Path::new(&config_file) | ||||||||
.canonicalize() | ||||||||
.ok() | ||||||||
.and_then(|path| path.parent().map(|path| path.to_path_buf())); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
(config, config_directory) | ||||||||
} | ||||||||
Err(error) => { | ||||||||
error!("Config file not in correct format: {}", error); | ||||||||
std::process::exit(1); | ||||||||
|
@@ -636,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. | ||||||||
Comment on lines
+646
to
+647
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
// The working directory needs to be an absolute path to match with paths in different directories. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This doesn't explain why relative path won't work. Can we either clarify that? |
||||||||
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. | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||
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); | ||||||||
|
@@ -649,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; | ||||||||
} | ||||||||
|
||||||||
|
@@ -671,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; | ||||||||
} | ||||||||
|
||||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.