diff --git a/src/app.rs b/src/app.rs index e817dd45..8177d7e9 100644 --- a/src/app.rs +++ b/src/app.rs @@ -82,10 +82,11 @@ fn add<'a, T: Io, S: 'a + Storage>( Ok(()) } -fn calculate_total(io: &impl Io, d: &str, mut total: u64) -> io::Result { +fn calculate_total(io: &impl Io, d: &str, extra: u64) -> io::Result { let stdout = &mut io.stdout(); let a = io.read_dir(&("cdt0/".to_owned() + d))?; let an = a.len() as u64; + let mut total = 0; let state = &mut State::new(stdout); for (ai, ia) in a.iter().enumerate() { let b = io.read_dir(&ia.path())?; @@ -97,16 +98,16 @@ fn calculate_total(io: &impl Io, d: &str, mut total: u64) -> io::Result { total += d; } let p = (bn * ai as u64 + bi as u64) as f64 / (an * bn) as f64; - let e = (total as f64) / p; + let e = (extra + total) as f64 / p; let s = "size: ~".to_string() - + &mb(e as u64) + + &mb(extra + e as u64) + ". " + &((p * 100.0) as u64).to_string() + "%."; state.set(&s)?; } } - Ok(total) + Ok(extra + total) } pub fn run(io: &impl Io) -> Result<(), String> {