Lints and suggestions for the Nix programming language
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

walker.next: don't stop until `self.dirs` is empty (#57)

Closes: #38

authored by

ilkecan and committed by
GitHub
96157609 cd187b2b

+22 -15
+22 -15
bin/src/dirs.rs
··· 45 45 impl Iterator for Walker { 46 46 type Item = PathBuf; 47 47 fn next(&mut self) -> Option<Self::Item> { 48 - if let Some(dir) = self.dirs.pop() { 49 - if dir.is_dir() { 50 - if let Match::None | Match::Whitelist(_) = self.ignore.matched(&dir, true) { 51 - for entry in fs::read_dir(&dir).ok()? { 52 - let entry = entry.ok()?; 53 - let path = entry.path(); 54 - if path.is_dir() { 55 - self.dirs.push(path); 56 - } else if path.is_file() { 57 - if let Match::None | Match::Whitelist(_) = 58 - self.ignore.matched(&path, false) 59 - { 60 - self.files.push(path); 48 + self.files.pop().or_else(|| { 49 + while let Some(dir) = self.dirs.pop() { 50 + if dir.is_dir() { 51 + if let Match::None | Match::Whitelist(_) = self.ignore.matched(&dir, true) { 52 + let mut found = false; 53 + for entry in fs::read_dir(&dir).ok()? { 54 + let entry = entry.ok()?; 55 + let path = entry.path(); 56 + if path.is_dir() { 57 + self.dirs.push(path); 58 + } else if path.is_file() { 59 + if let Match::None | Match::Whitelist(_) = 60 + self.ignore.matched(&path, false) 61 + { 62 + found = true; 63 + self.files.push(path); 64 + } 61 65 } 66 + } 67 + if found { 68 + break; 62 69 } 63 70 } 64 71 } 65 72 } 66 - } 67 - self.files.pop() 73 + self.files.pop() 74 + }) 68 75 } 69 76 } 70 77