mirror of
https://github.com/ClementTsang/bottom
synced 2024-11-10 14:44:18 +00:00
refactor: fix macro formatting in disk data collection code (#1363)
This commit is contained in:
parent
a1168cac67
commit
c10779ecc0
1 changed files with 31 additions and 22 deletions
|
@ -341,20 +341,25 @@ impl DataCollection {
|
||||||
|
|
||||||
for (itx, device) in disks.iter().enumerate() {
|
for (itx, device) in disks.iter().enumerate() {
|
||||||
let checked_name = {
|
let checked_name = {
|
||||||
cfg_if::cfg_if! {
|
#[cfg(target_os = "windows")]
|
||||||
if #[cfg(target_os = "windows")] {
|
{
|
||||||
match &device.volume_name {
|
match &device.volume_name {
|
||||||
Some(volume_name) => Some(volume_name.as_str()),
|
Some(volume_name) => Some(volume_name.as_str()),
|
||||||
None => device.name.split('/').last(),
|
None => device.name.split('/').last(),
|
||||||
}
|
}
|
||||||
} else {
|
}
|
||||||
#[cfg(feature = "zfs")]
|
#[cfg(not(target_os = "windows"))]
|
||||||
if ! device.name.starts_with('/'){
|
{
|
||||||
|
#[cfg(feature = "zfs")]
|
||||||
|
{
|
||||||
|
if !device.name.starts_with('/') {
|
||||||
Some(device.name.as_str()) // use the whole zfs dataset name
|
Some(device.name.as_str()) // use the whole zfs dataset name
|
||||||
} else {
|
} else {
|
||||||
device.name.split('/').last()
|
device.name.split('/').last()
|
||||||
}
|
}
|
||||||
#[cfg(not(feature = "zfs"))]
|
}
|
||||||
|
#[cfg(not(feature = "zfs"))]
|
||||||
|
{
|
||||||
device.name.split('/').last()
|
device.name.split('/').last()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -362,22 +367,26 @@ impl DataCollection {
|
||||||
|
|
||||||
if let Some(checked_name) = checked_name {
|
if let Some(checked_name) = checked_name {
|
||||||
let io_device = {
|
let io_device = {
|
||||||
cfg_if::cfg_if! {
|
#[cfg(target_os = "macos")]
|
||||||
if #[cfg(target_os = "macos")] {
|
{
|
||||||
use std::sync::OnceLock;
|
use regex::Regex;
|
||||||
use regex::Regex;
|
use std::sync::OnceLock;
|
||||||
|
|
||||||
// Must trim one level further for macOS!
|
// Must trim one level further for macOS!
|
||||||
static DISK_REGEX: OnceLock<Regex> = OnceLock::new();
|
static DISK_REGEX: OnceLock<Regex> = OnceLock::new();
|
||||||
if let Some(new_name) = DISK_REGEX.get_or_init(|| Regex::new(r"disk\d+").unwrap()).find(checked_name) {
|
if let Some(new_name) = DISK_REGEX
|
||||||
io.get(new_name.as_str())
|
.get_or_init(|| Regex::new(r"disk\d+").unwrap())
|
||||||
} else {
|
.find(checked_name)
|
||||||
None
|
{
|
||||||
}
|
io.get(new_name.as_str())
|
||||||
} else {
|
} else {
|
||||||
io.get(checked_name)
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#[cfg(not(target_os = "macos"))]
|
||||||
|
{
|
||||||
|
io.get(checked_name)
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Some(io_device) = io_device {
|
if let Some(io_device) = io_device {
|
||||||
|
|
Loading…
Reference in a new issue