This commit is contained in:
Max Smirnov 2022-08-22 16:20:24 +03:00
parent 3ead212fe7
commit 0a4ec4ecd4
No known key found for this signature in database
GPG Key ID: 2C3271EA73A3F336

View File

@ -1,5 +1,10 @@
use crate::error::Result; use crate::error::Result;
use std::{fs::{read_dir, ReadDir}, path::Path, result::Result as StdResult, iter::once}; use std::{
fs::{read_dir, ReadDir},
iter::once,
path::Path,
result::Result as StdResult,
};
/// The on disk layout for served repos is `<service>/<user>/<repo>` /// The on disk layout for served repos is `<service>/<user>/<repo>`
/// so to get the amount of repos, we just have to count everything /// so to get the amount of repos, we just have to count everything
@ -15,13 +20,11 @@ where
.flat_map(sub_directories) .flat_map(sub_directories)
.flat_map(sub_directories) .flat_map(sub_directories)
.flat_map(sub_directories) .flat_map(sub_directories)
.count() .count())
)
} }
fn sub_directories(dir: ReadDir) -> impl Iterator<Item = ReadDir> { fn sub_directories(dir: ReadDir) -> impl Iterator<Item = ReadDir> {
dir dir.filter_map(StdResult::ok)
.filter_map(StdResult::ok)
.filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false)) .filter(|entry| entry.file_type().map(|ft| ft.is_dir()).unwrap_or(false))
.filter_map(|entry| read_dir(entry.path()).ok()) .filter_map(|entry| read_dir(entry.path()).ok())
} }