Skip to content

Commit

Permalink
bug: fix use of skip_current_dir
Browse files Browse the repository at this point in the history
The method sometimes destroyed an internal invariant by not decreasing
`oldest_opened`. That then leads to panics in `push`. We fix this by
calling the canonical `pop` function, which is what should have happened
from the beginning.

This includes a regression test that fails without this fix.

Fixes #118, Closes #124
  • Loading branch information
LukasKalbertodt authored and BurntSushi committed Jul 20, 2019
1 parent 4d42a69 commit af0cf7a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
5 changes: 1 addition & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,10 +724,7 @@ impl IntoIter {
/// [`filter_entry`]: #method.filter_entry
pub fn skip_current_dir(&mut self) {
if !self.stack_list.is_empty() {
self.stack_list.pop();
}
if !self.stack_path.is_empty() {
self.stack_path.pop();
self.pop();
}
}

Expand Down
20 changes: 20 additions & 0 deletions src/tests/recursive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -990,3 +990,23 @@ fn same_file_system() {
];
assert_eq!(expected, r.sorted_paths());
}

// Tests that skip_current_dir doesn't destroy internal invariants.
//
// See: https://github.com/BurntSushi/walkdir/issues/118
#[test]
fn regression_skip_current_dir() {
let dir = Dir::tmp();
dir.mkdirp("foo/a/b");
dir.mkdirp("foo/1/2");

let mut wd = WalkDir::new(dir.path()).max_open(1).into_iter();
wd.next();
wd.next();
wd.next();
wd.next();

wd.skip_current_dir();
wd.skip_current_dir();
wd.next();
}

0 comments on commit af0cf7a

Please sign in to comment.