dysk_cli/
normal.rs

1use {
2    lfs_core::Mount,
3    std::path::Path,
4};
5
6/// Determine whether the mounted filesystem is "normal", which
7/// means it should be listed in standard
8pub fn is_normal(m: &Mount) -> bool {
9    (
10        m.stats().is_some()
11        || m.is_unreachable()
12    )
13    && (
14        m.disk.is_some() // by default only fs with disks are shown
15        || m.info.fs_type == "zfs" // unless it's zfs - see https://github.com/Canop/dysk/issues/32
16        || m.is_remote()
17    )
18    && m.disk.as_ref().map_or(true, |d| !d.image) // not real
19    && !m.info.bound // removing bound mounts
20    && m.info.fs_type != "squashfs" // quite ad-hoc...
21    && !is_system_path(&m.info.mount_point)
22}
23
24#[cfg(target_os = "macos")]
25fn is_system_path(path: &Path) -> bool {
26    let Some(path) = path.to_str() else {
27        return false;
28    };
29    if path == "/" {
30        return true;
31    }
32    if path.starts_with("/System") && !path.starts_with("/System/Volumes/Data") {
33        return true;
34    }
35    if path.starts_with("/Library/Developer") {
36        return true;
37    }
38    false
39}
40
41#[cfg(target_os = "linux")]
42fn is_system_path(path: &Path) -> bool {
43    path.starts_with("/boot")
44}
45
46#[cfg(target_os = "windows")]
47fn is_system_path(_path: &Path) -> bool {
48    false
49}