mod file_systems;
mod usage;
cfg_if::cfg_if! {
if #[cfg(target_os = "linux")] {
mod linux;
pub use linux::*;
} else if #[cfg(target_os = "macos")] {
mod other;
use other::*;
mod macos;
pub use macos::*;
} else {
mod other;
use other::*;
}
}
use file_systems::*;
use usage::*;
use super::{DiskHarvest, keep_disk_entry};
use crate::collection::DataCollector;
pub fn get_disk_usage(collector: &DataCollector) -> anyhow::Result<Vec<DiskHarvest>> {
let disk_filter = &collector.filters.disk_filter;
let mount_filter = &collector.filters.mount_filter;
let mut vec_disks: Vec<DiskHarvest> = Vec::new();
for partition in physical_partitions()? {
let name = partition.get_device_name();
let mount_point = partition.mount_point().to_string_lossy().to_string();
if keep_disk_entry(&name, &mount_point, disk_filter, mount_filter) {
if let Ok(usage) = partition.usage() {
let total = usage.total();
vec_disks.push(DiskHarvest {
free_space: Some(usage.free()),
used_space: Some(total - usage.available()),
total_space: Some(total),
mount_point,
name,
});
} else {
vec_disks.push(DiskHarvest {
free_space: None,
used_space: None,
total_space: None,
mount_point,
name,
});
}
}
}
Ok(vec_disks)
}