diff --git a/Cargo.lock b/Cargo.lock index 74e06dc8..3452d3d6 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -164,18 +164,18 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.8" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84b3edb18336f4df585bc9aa31dd99c036dfa5dc5e9a2939a722a188f3a8970d" +checksum = "64acc1846d54c1fe936a78dc189c34e28d3f5afc348403f28ecf53660b9b8462" dependencies = [ "clap_builder", ] [[package]] name = "clap_builder" -version = "4.5.8" +version = "4.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c1c09dd5ada6c6c78075d6fd0da3f90d8080651e2d6cc8eb2f1aaa4034ced708" +checksum = "6fb8393d67ba2e7bfaf28a23458e4e2b543cc73a99595511eb207fdb8aede942" dependencies = [ "anstream", "anstyle", diff --git a/src/find/matchers/mod.rs b/src/find/matchers/mod.rs index 6e3a3e39..f41f1edd 100644 --- a/src/find/matchers/mod.rs +++ b/src/find/matchers/mod.rs @@ -699,6 +699,11 @@ fn build_matcher_tree( config.today_start = true; None } + "-noleaf" => { + // No change of behavior + config.no_leaf_dirs = true; + None + } "-d" | "-depth" => { // TODO add warning if it appears after actual testing criterion config.depth_first = true; diff --git a/src/find/mod.rs b/src/find/mod.rs index 680f84d2..dda6bc0d 100644 --- a/src/find/mod.rs +++ b/src/find/mod.rs @@ -22,6 +22,7 @@ pub struct Config { help_requested: bool, version_requested: bool, today_start: bool, + no_leaf_dirs: bool, } impl Default for Config { @@ -35,6 +36,10 @@ impl Default for Config { help_requested: false, version_requested: false, today_start: false, + // Directory information and traversal are done by walkdir, + // and this configuration field will exist as + // a compatibility item for GNU findutils. + no_leaf_dirs: false, } } } @@ -158,6 +163,7 @@ fn process_dir<'a>( } Ok(entry) => { let mut matcher_io = matchers::MatcherIO::new(deps); + if matcher.matches(&entry, &mut matcher_io) { found_count += 1; } @@ -1254,6 +1260,15 @@ mod tests { ], &deps, ); + } + + #[test] + #[cfg(unix)] + fn test_noleaf() { + use crate::find::tests::FakeDependencies; + + let deps = FakeDependencies::new(); + let rc = find_main(&["find", "./test_data/simple/subdir", "-noleaf"], &deps); assert_eq!(rc, 0); } diff --git a/tests/find_cmd_tests.rs b/tests/find_cmd_tests.rs index 73c0cc7c..c77d6290 100644 --- a/tests/find_cmd_tests.rs +++ b/tests/find_cmd_tests.rs @@ -904,5 +904,16 @@ fn find_ignore_readdir_race() { ]) .assert() .success() +} + +#[test] +#[serial(working_dir)] +fn find_noleaf() { + Command::cargo_bin("find") + .expect("found binary") + .args(["test_data/simple/subdir", "-noleaf"]) + .assert() + .success() + .stdout(predicate::str::contains("test_data/simple/subdir")) .stderr(predicate::str::is_empty()); }