From 3eb1477ffc0555927870e6e319929cb0f935a282 Mon Sep 17 00:00:00 2001 From: lukas-heiligenbrunner Date: Tue, 6 Dec 2022 22:22:24 +0100 Subject: [PATCH] use actual system mdstat file --- src/main.rs | 2 +- src/parser/lsblk_parser.rs | 4 ++-- src/parser/mdstat_parser.rs | 10 +++------- 3 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/main.rs b/src/main.rs index 10e1f3c..974a213 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,4 +26,4 @@ async fn main() -> Result<(), rocket::Error> { .await?; Ok(()) -} \ No newline at end of file +} diff --git a/src/parser/lsblk_parser.rs b/src/parser/lsblk_parser.rs index 5cd20e5..0831413 100644 --- a/src/parser/lsblk_parser.rs +++ b/src/parser/lsblk_parser.rs @@ -62,5 +62,5 @@ pub fn parse_lsblk() -> Vec { if d.kind != "disk" { continue; }; disks.push(Disk { name: d.name, size: d.size }); } - disks -} \ No newline at end of file + return disks; +} diff --git a/src/parser/mdstat_parser.rs b/src/parser/mdstat_parser.rs index 8cc7005..4f3c674 100644 --- a/src/parser/mdstat_parser.rs +++ b/src/parser/mdstat_parser.rs @@ -20,8 +20,7 @@ pub struct MdRaid { } pub fn parse_mdstat() -> MdRaidSystem { - // let mdstat_path = "/proc/mdstat"; - let mdstat_path = "testmdstat.txt"; + let mdstat_path = "/proc/mdstat"; return match fs::read_to_string(mdstat_path) { Ok(contents) => parse_mdstat_str(contents), Err(_) => MdRaidSystem{ @@ -40,10 +39,7 @@ fn parse_mdstat_str(contents: String) -> MdRaidSystem { } for cap in RE.captures_iter(&contents) { - if cap.len() != 5 { - // todo error handling - continue - } else { + if cap.len() == 5 { let devicesplit = cap[4].split(" "); let mut devices = Vec::new(); for i in devicesplit { @@ -166,4 +162,4 @@ md0 : active raid1 sdb1[1] sda1[0] unused devices: "#.to_string())).to_string(), exp); } -} \ No newline at end of file +}