Skip to content

Commit 16552fc

Browse files
committed
fix: avoid skipping broken symlinks with --min-depth and --follow
DirEntry::depth() is None for broken symlinks; is_none_or would treat None as satisfying the "below min-depth" check and skip every such entry. Add regression test matching `fd --min-depth 1 -L . testdir` with a nested dangling symlink.
1 parent a665a3b commit 16552fc

3 files changed

Lines changed: 22 additions & 1 deletion

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## Bugfixes
44
- Handle invalid working directories gracefully when using `--full-path`, see #1900 (@Xavrir).
5+
- Do not skip dangling symlinks when using `--min-depth` together with `--follow` (`-L`): broken-symlink entries have no walk depth and were incorrectly filtered. see #1962 (@cuiweixie).
56

67
# 10.4.2
78

src/walk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -516,7 +516,7 @@ impl WorkerState {
516516
};
517517

518518
if let Some(min_depth) = config.min_depth
519-
&& entry.depth().is_none_or(|d| d < min_depth)
519+
&& entry.depth().is_some_and(|d| d < min_depth)
520520
{
521521
return WalkState::Continue;
522522
}

tests/tests.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,26 @@ fn test_min_depth() {
11331133
);
11341134
}
11351135

1136+
/// Regression: `fd --min-depth 1 -L . testdir` must list a dangling symlink under `testdir/sub/`.
1137+
/// (`DirEntry::broken_symlink` has no depth; `is_none_or` incorrectly skipped it.)
1138+
#[cfg(unix)]
1139+
#[test]
1140+
fn test_min_depth_follow_broken_symlink_nested() {
1141+
use std::os::unix::fs::symlink;
1142+
1143+
// `testenv` always creates `symlink` -> `one/two`; that directory must exist.
1144+
let dirs = &["one/two", "testdir/sub"];
1145+
let files: &[&str] = &[];
1146+
let te = TestEnv::new(dirs, files);
1147+
symlink("/noexistent", te.test_root().join("testdir/sub/broken")).expect("symlink");
1148+
1149+
te.assert_output(
1150+
&["--min-depth", "1", "-L", ".", "testdir"],
1151+
"testdir/sub/
1152+
testdir/sub/broken",
1153+
);
1154+
}
1155+
11361156
/// Exact depth (--exact-depth)
11371157
#[test]
11381158
fn test_exact_depth() {

0 commit comments

Comments
 (0)