Signed-off-by: Slendi <slendi@socopon.com>
This commit is contained in:
2026-01-25 19:51:41 +02:00
commit 98cede7854
8 changed files with 1119 additions and 0 deletions

35
src/main.rs Normal file
View File

@@ -0,0 +1,35 @@
use std::path::PathBuf;
use clap::Parser;
use humansize::DECIMAL;
#[derive(Debug, Parser)]
struct Args {
path: PathBuf,
}
fn compute_size(path: PathBuf) -> Result<u64, std::io::Error> {
if path.is_dir() {
std::fs::read_dir(path)?.fold(Ok(0_u64), |counter, entry| -> Result<u64, std::io::Error> {
if let Ok(counter) = counter {
Ok(counter + compute_size(entry?.path())?)
} else {
counter
}
})
} else {
Ok(std::fs::metadata(path)?.len())
}
}
fn main() {
let args = Args::parse();
match compute_size(args.path) {
Ok(size) => println!(
"Computed size sum: {} ({} bytes)",
humansize::format_size(size, DECIMAL),
size
),
Err(error) => eprintln!("Failed to fetch size: {}", error),
}
}