mirror of
https://github.com/sharkdp/fd.git
synced 2026-08-30 17:07:43 +08:00
ignore_contain now has higher precedence than root check.
This commit is contained in:
+16
-15
@@ -461,11 +461,22 @@ impl WorkerState {
|
||||
return WalkState::Quit;
|
||||
}
|
||||
|
||||
let entry = match entry {
|
||||
Ok(ref e) if e.depth() == 0 => {
|
||||
if let Ok(e) = &entry {
|
||||
let entry_path = e.path();
|
||||
if entry_path.is_dir()
|
||||
&& config
|
||||
.ignore_contain
|
||||
.iter()
|
||||
.any(|ic| entry_path.join(ic).exists())
|
||||
{
|
||||
return WalkState::Skip;
|
||||
}
|
||||
if e.depth() == 0 {
|
||||
// Skip the root directory entry.
|
||||
return WalkState::Continue;
|
||||
}
|
||||
}
|
||||
let entry = match entry {
|
||||
Ok(e) => DirEntry::normal(e),
|
||||
Err(ignore::Error::WithPath {
|
||||
path,
|
||||
@@ -498,25 +509,15 @@ impl WorkerState {
|
||||
}
|
||||
};
|
||||
|
||||
// Check the depth & name first, since they don't require metadata.
|
||||
let entry_path = entry.path();
|
||||
|
||||
// Filter out directories containing a given name.
|
||||
if entry_path.is_dir()
|
||||
&& config
|
||||
.ignore_contain
|
||||
.iter()
|
||||
.any(|ic| entry_path.join(ic).exists())
|
||||
{
|
||||
return WalkState::Skip;
|
||||
}
|
||||
|
||||
if let Some(min_depth) = config.min_depth
|
||||
&& entry.depth().is_none_or(|d| d < min_depth)
|
||||
{
|
||||
return WalkState::Continue;
|
||||
}
|
||||
|
||||
// Check the name first, since it doesn't require metadata
|
||||
let entry_path = entry.path();
|
||||
|
||||
let search_str: Cow<OsStr> = if config.search_full_path {
|
||||
let path_abs_buf = filesystem::path_absolute_form(entry_path)
|
||||
.expect("Retrieving absolute path succeeds");
|
||||
|
||||
+8
-1
@@ -2735,7 +2735,7 @@ fn test_ignore_contain() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignore_contain_has_highest_precedence() {
|
||||
fn test_ignore_contain_precedence_over_depth_check() {
|
||||
let te = TestEnv::new(
|
||||
&["include", "exclude", "exclude/sub"],
|
||||
&[
|
||||
@@ -2751,3 +2751,10 @@ fn test_ignore_contain_has_highest_precedence() {
|
||||
expected,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_ignore_contain_precedence_over_root_check() {
|
||||
let te = TestEnv::new(&["include"], &["CACHEDIR.TAG", "top", "include/foo"]);
|
||||
let expected = "";
|
||||
te.assert_output(&["--ignore-contain=CACHEDIR.TAG", "."], expected);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user