diff --git a/src/count.rs b/src/count.rs new file mode 100644 index 0000000..a4222d5 --- /dev/null +++ b/src/count.rs @@ -0,0 +1,24 @@ +use crate::error::Result; +use std::{fs::read_dir, path::Path, result::Result as StdResult}; + +pub(crate) fn count_repositories

(repo_path: P) -> Result +where + P: AsRef, +{ + Ok(read_dir(repo_path)? + .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()) +} diff --git a/src/main.rs b/src/main.rs index 6e35e27..d68ec84 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,3 +1,5 @@ +#![type_length_limit = "2257138"] + #[macro_use] extern crate actix_web; #[macro_use] @@ -9,6 +11,7 @@ extern crate serde_derive; mod cache; mod config; +mod count; mod error; mod service; mod statics; @@ -34,6 +37,7 @@ use std::{ fs::create_dir_all, path::Path, process::Command, + sync::atomic::Ordering, sync::Arc, time::{Duration, SystemTime}, }; @@ -169,6 +173,7 @@ fn hoc_request( let repo = Repository::init_bare(file)?; repo.remote_add_fetch("origin", "refs/heads/*:refs/heads/*")?; repo.remote_set_url("origin", &url)?; + REPO_COUNT.fetch_add(1, Ordering::Relaxed); } pull(&path)?; let (hoc, head) = hoc(&service_path, &state.repos, &state.cache)?; diff --git a/src/statics.rs b/src/statics.rs index 2e4757e..53e0576 100644 --- a/src/statics.rs +++ b/src/statics.rs @@ -1,3 +1,5 @@ +use crate::{config::Opt, count::count_repositories}; +use std::sync::atomic::AtomicUsize; use structopt::StructOpt; pub struct VersionInfo<'a> { @@ -15,4 +17,6 @@ pub(crate) const FAVICON: &[u8] = include_bytes!("../static/favicon32.png"); lazy_static! { pub(crate) static ref CLIENT: reqwest::Client = reqwest::Client::new(); pub(crate) static ref OPT: Opt = Opt::from_args(); + pub(crate) static ref REPO_COUNT: AtomicUsize = + AtomicUsize::new(count_repositories(&OPT.outdir).unwrap()); }