+
Skip to content
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
5 changes: 5 additions & 0 deletions src/find/matchers/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -692,6 +692,11 @@ fn build_matcher_tree(

return Ok((i, top_level_matcher.build()));
}
"-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;
Expand Down
17 changes: 17 additions & 0 deletions src/find/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub struct Config {
sorted_output: bool,
help_requested: bool,
version_requested: bool,
no_leaf_dirs: bool,
}

impl Default for Config {
Expand All @@ -33,6 +34,10 @@ impl Default for Config {
sorted_output: false,
help_requested: false,
version_requested: 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,
}
}
}
Expand Down Expand Up @@ -156,6 +161,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;
}
Expand Down Expand Up @@ -1219,4 +1225,15 @@ mod tests {

assert_eq!(rc, 0);
}

#[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);
}
}
12 changes: 12 additions & 0 deletions tests/find_cmd_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -881,3 +881,15 @@ fn find_samefile() {
.stdout(predicate::str::is_empty())
.stderr(predicate::str::contains("not-exist-file"));
}

#[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());
}
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载