use std::io;
use std::path::Path;
use rustix::fs;
use crate::units::ByteSize;
pub fn total_space(path: &Path) -> io::Result<ByteSize> {
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
let stat = fs::statfs(path)?;
#[cfg(target_os = "linux")]
let block_size = u64::try_from(stat.f_bsize).unwrap_or(0);
#[cfg(target_os = "macos")]
let block_size = u64::from(stat.f_bsize);
Ok(ByteSize::b(block_size.saturating_mul(stat.f_blocks)))
}
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
let stat = fs::statvfs(path)?;
Ok(ByteSize::b(stat.f_frsize.saturating_mul(stat.f_blocks)))
}
}