blob: cbc99d9fa1efe25d2e1fd3e6d9c3ab81c88103b7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
//! Linux-specific things for Heim disk data collection.
use heim::disk::Partition;
pub fn get_device_name(partition: &Partition) -> String {
if let Some(device) = partition.device() {
// See if this disk is actually mounted elsewhere on Linux...
// This is a workaround to properly map I/O in some cases (i.e. disk encryption), see
// https://github.com/ClementTsang/bottom/issues/419
if let Ok(path) = std::fs::read_link(device) {
if path.is_absolute() {
path.into_os_string()
} else {
let mut combined_path = std::path::PathBuf::new();
combined_path.push(device);
combined_path.pop(); // Pop the current file...
combined_path.push(path);
if let Ok(canon_path) = std::fs::canonicalize(combined_path) {
// Resolve the local path into an absolute one...
canon_path.into_os_string()
} else {
device.to_os_string()
}
}
} else {
device.to_os_string()
}
.into_string()
.unwrap_or_else(|_| "Name Unavailable".to_string())
} else {
"Name Unavailable".to_string()
}
}
|