Skip to content

ignore: fix panic in walk iterator when min_depth skips root#3319

Open
majiayu000 wants to merge 1 commit intoBurntSushi:masterfrom
majiayu000:fix/issue-3286-walk-min-depth-panic
Open

ignore: fix panic in walk iterator when min_depth skips root#3319
majiayu000 wants to merge 1 commit intoBurntSushi:masterfrom
majiayu000:fix/issue-3286-walk-min-depth-panic

Conversation

@majiayu000
Copy link
Copy Markdown

Summary

  • Fix panic at self.ig.parent().unwrap() when min_depth > 0 causes the root entry to be skipped
  • When min_depth > 0, WalkDir never yields the root at depth 0, so add_child() is never called for it. But WalkEventIter still emits an Exit event, and parent() returns None since self.ig is already at the root level
  • Replace unwrap() with if let Some(parent) guard to skip the pop when there is no parent

Test plan

  • Added min_depth_max_depth_no_panic regression test covering both single-threaded and parallel walks
  • cargo test --workspace — all tests pass
  • cargo fmt --all --check — clean
  • cargo build --workspace — clean

Closes #3286

When min_depth > 0, WalkDir skips the root entry at depth 0, so Walk
never calls add_child() for it. But WalkEventIter still emits an Exit
event for the root directory. The unwrap() on parent() panics because
self.ig has no parent at the root level.

Replace unwrap() with an if-let guard that simply skips the pop when
there is no parent.

Closes BurntSushi#3286

Signed-off-by: majiayu000 <1835304752@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ignore: Panic occur when use walk with walkbuilder set both min_depth and max_path to some(1) and visit the system root_path

1 participant