mirror of
https://github.com/ClementTsang/bottom.git
synced 2025-07-21 20:54:43 +02:00
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
This commit is contained in:
parent
4605e88927
commit
2e6ac01f99
@ -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
|
||||
|
||||
|
@ -76,6 +76,7 @@ impl Partition {
|
||||
|
||||
/// Returns the usage stats for this partition.
|
||||
pub fn usage(&self) -> anyhow::Result<Usage> {
|
||||
// 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<Partition> {
|
||||
// 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<Vec<Partition>> {
|
||||
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user