From 2e6ac01f9951918f459695dd901e35329e06a635 Mon Sep 17 00:00:00 2001 From: Clement Tsang <34804052+ClementTsang@users.noreply.github.com> Date: Wed, 16 Jul 2025 22:15:55 -0400 Subject: [PATCH] bug: fix parsing issue around certain disk names (#1755) * bug: fix parsing issue around certain disk names Turns out that in /proc/mount disk names may have weird escape characters - these need to be changed when parsing it. * update changelog * back to the slow * Add test --- CHANGELOG.md | 1 + src/collection/disks/unix/linux/partition.rs | 30 ++++++++++++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10560551..b67f7d59 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -42,6 +42,7 @@ That said, these are more guidelines rather than hardset rules, though the proje - [#1663](https://github.com/ClementTsang/bottom/pull/1663): Fix network graphs using log scaling having broken lines when a point was 0. - [#1683](https://github.com/ClementTsang/bottom/pull/1683): Fix graph lines potentially showing up behind legends. - [#1701](https://github.com/ClementTsang/bottom/pull/1701): Fix process kill dialog occasionally causing panics. +- [#1755](https://github.com/ClementTsang/bottom/pull/1755): Fix missing stats/incorrect mount name for certain entries in the disk widget. ### Changes diff --git a/src/collection/disks/unix/linux/partition.rs b/src/collection/disks/unix/linux/partition.rs index 961290c5..d02e2797 100644 --- a/src/collection/disks/unix/linux/partition.rs +++ b/src/collection/disks/unix/linux/partition.rs @@ -76,6 +76,7 @@ impl Partition { /// Returns the usage stats for this partition. pub fn usage(&self) -> anyhow::Result { + // TODO: This might be unoptimal. let path = self .mount_point .to_str() @@ -103,12 +104,24 @@ impl Partition { } } +fn fix_mount_point(s: &str) -> String { + const ESCAPED_BACKSLASH: &str = "\\134"; + const ESCAPED_SPACE: &str = "\\040"; + const ESCAPED_TAB: &str = "\\011"; + const ESCAPED_NEWLINE: &str = "\\012"; + + s.replace(ESCAPED_BACKSLASH, "\\") + .replace(ESCAPED_SPACE, " ") + .replace(ESCAPED_TAB, "\t") + .replace(ESCAPED_NEWLINE, "\n") +} + impl FromStr for Partition { type Err = anyhow::Error; fn from_str(line: &str) -> anyhow::Result { // Example: `/dev/sda3 /home ext4 rw,relatime,data=ordered 0 0` - let mut parts = line.splitn(5, ' '); + let mut parts = line.trim_start().splitn(5, ' '); let device = match parts.next() { Some("none") => None, @@ -117,8 +130,9 @@ impl FromStr for Partition { bail!("missing device"); } }; + let mount_point = match parts.next() { - Some(point) => PathBuf::from(point), + Some(mount_point) => PathBuf::from(fix_mount_point(mount_point)), None => { bail!("missing mount point"); } @@ -191,3 +205,15 @@ pub(crate) fn physical_partitions() -> anyhow::Result> { Ok(results) } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_fix_mount_point() { + let line = "/run/media/test/Samsung\\040980"; + + assert_eq!(fix_mount_point(line), "/run/media/test/Samsung 980"); + } +}