diff --git a/src/count.rs b/src/count.rs index 4a74b27..d663ed8 100644 --- a/src/count.rs +++ b/src/count.rs @@ -1,5 +1,5 @@ use crate::error::Result; -use std::{fs::read_dir, path::Path, result::Result as StdResult}; +use std::{fs::{read_dir, ReadDir}, path::Path, result::Result as StdResult, iter::once}; #[instrument] pub(crate) fn count_repositories

(repo_path: P) -> Result @@ -8,20 +8,17 @@ where { trace!("Counting repositories"); std::fs::create_dir_all(&repo_path)?; - Ok(read_dir(repo_path)? + Ok(once(read_dir(repo_path)?) + .flat_map(sub_directories) + .flat_map(sub_directories) + .flat_map(sub_directories) + .count() + ) +} + +fn sub_directories(dir: ReadDir) -> impl Iterator { + dir .filter_map(StdResult::ok) .filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false)) - .map(|entry| read_dir(entry.path())) - .filter_map(StdResult::ok) - .flat_map(|dir| { - dir.filter_map(StdResult::ok) - .filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false)) - }) - .map(|entry| read_dir(entry.path())) - .filter_map(StdResult::ok) - .flat_map(|dir| { - dir.filter_map(StdResult::ok) - .filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false)) - }) - .count()) + .filter_map(|entry| read_dir(entry.path()).ok()) }