use anyhow::Result;
use ignore::WalkBuilder;
use std::path::Path;
pub fn dir_size_bytes(root: &Path) -> Result<u64> {
if !root.exists() {
return Ok(0);
}
let mut total: u64 = 0;
for dent in WalkBuilder::new(root).hidden(false).build() {
let dent = dent?;
if dent.file_type().map(|t| t.is_file()).unwrap_or(false) {
if let Ok(md) = dent.metadata() {
total = total.saturating_add(md.len());
}
}
}
Ok(total)
}