diff --git a/src/find/matchers/mod.rs b/src/find/matchers/mod.rs index 8e7d5cf8..0c885de9 100644 --- a/src/find/matchers/mod.rs +++ b/src/find/matchers/mod.rs @@ -695,6 +695,20 @@ fn build_matcher_tree( return Ok((i, top_level_matcher.build())); } + // In our implementation, including the `-exec` parameter, + // it is always run in a single thread. + // Therefore, there is no race condition for now. + // and we currently only add the corresponding fields in Config. + // + // Related: https://github.com/uutils/findutils/pull/411#issuecomment-2210638686 + "-ignore_readdir_race" => { + config.ignore_readdir_race = true; + None + } + "-noignore_readdir_race" => { + config.ignore_readdir_race = false; + None + } "-daystart" => { config.today_start = true; None diff --git a/src/find/mod.rs b/src/find/mod.rs index 738562db..4c98e405 100644 --- a/src/find/mod.rs +++ b/src/find/mod.rs @@ -21,6 +21,7 @@ pub struct Config { sorted_output: bool, help_requested: bool, version_requested: bool, + ignore_readdir_race: bool, today_start: bool, no_leaf_dirs: bool, } @@ -35,6 +36,8 @@ impl Default for Config { sorted_output: false, help_requested: false, version_requested: false, + // For compat: doesn't change anything + ignore_readdir_race: false, today_start: false, // Directory information and traversal are done by walkdir, // and this configuration field will exist as @@ -1232,17 +1235,6 @@ 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); - } - #[test] fn find_maxdepth_and() { let deps = FakeDependencies::new(); @@ -1300,4 +1292,35 @@ mod tests { assert_eq!(rc, 0); } + + #[test] + #[cfg(unix)] + fn test_ignore_readdir_race() { + use crate::find::tests::FakeDependencies; + + let deps = FakeDependencies::new(); + let rc = find_main( + &["find", "./test_data/simple/subdir", "-ignore_readdir_race"], + &deps, + ); + + assert_eq!(rc, 0); + } + + #[test] + fn test_noignore_readdir_race() { + use crate::find::tests::FakeDependencies; + + let deps = FakeDependencies::new(); + let rc = find_main( + &[ + "find", + "./test_data/simple/subdir", + "-noignore_readdir_race", + ], + &deps, + ); + + assert_eq!(rc, 0); + } } diff --git a/tests/find_cmd_tests.rs b/tests/find_cmd_tests.rs index 20fa1a19..d3e0770d 100644 --- a/tests/find_cmd_tests.rs +++ b/tests/find_cmd_tests.rs @@ -910,18 +910,6 @@ fn find_samefile() { .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()); -} - #[test] #[serial(working_dir)] fn find_daystart() { @@ -946,3 +934,27 @@ fn find_daystart() { .success() .stderr(predicate::str::is_empty()); } + +#[test] +#[serial(working_dir)] +fn find_ignore_readdir_race() { + Command::cargo_bin("find") + .expect("found binary") + .args(["./test_data/simple/subdir", "-ignore_readdir_race"]) + .assert() + .success() + .stdout(predicate::str::contains("./test_data/simple/subdir")) + .stderr(predicate::str::is_empty()); +} + +#[test] +#[serial(working_dir)] +fn find_noignore_readdir_race() { + Command::cargo_bin("find") + .expect("found binary") + .args(["./test_data/simple/subdir", "-noignore_readdir_race"]) + .assert() + .success() + .stdout(predicate::str::contains("./test_data/simple/subdir")) + .stderr(predicate::str::is_empty()); +}