diff options
author | Andrew Gallant <jamslam@gmail.com> | 2015-09-27 08:27:18 +0300 |
---|---|---|
committer | Andrew Gallant <jamslam@gmail.com> | 2015-09-27 08:27:18 +0300 |
commit | 0964a448b7e128f603f4e78e049e84d25a0670d7 (patch) | |
tree | 2549bd53764689086f0331f15d9cab9f45996e81 | |
parent | 8a8a89202bfacc8317f049708ac321a1274b3a0e (diff) |
Tweak when max depth pruning happens.
-rw-r--r-- | src/lib.rs | 8 |
1 files changed, 7 insertions, 1 deletions
@@ -488,6 +488,12 @@ impl Iterator for Iter { } while !self.stack_list.is_empty() { self.depth = self.stack_list.len(); + if self.depth > self.opts.max_depth { + // If we've exceeded the max depth, pop the current dir + // so that we don't descend. + self.pop(); + continue; + } match self.stack_list.last_mut().unwrap().next() { None => self.pop(), Some(Err(err)) => return Some(Err(err)), @@ -522,7 +528,7 @@ impl Iter { if self.opts.follow_links && dent.file_type().is_symlink() { dent = itry!(self.follow(dent)); } - if dent.file_type().is_dir() && self.depth < self.opts.max_depth { + if dent.file_type().is_dir() { self.push(&dent); } if self.skippable() { None } else { Some(Ok(dent)) } |