From 230967832b595eb217f6bf62f2ac7172b18d91ce Mon Sep 17 00:00:00 2001 From: RGBCube Date: Wed, 21 May 2025 01:01:45 +0300 Subject: [PATCH] monitor: delete old code --- src/core.rs | 2 -- src/monitor.rs | 71 +------------------------------------------------- 2 files changed, 1 insertion(+), 72 deletions(-) diff --git a/src/core.rs b/src/core.rs index 07581aa..a3f4e33 100644 --- a/src/core.rs +++ b/src/core.rs @@ -1,8 +1,6 @@ pub struct SystemInfo { // Overall system details pub cpu_model: String, - pub architecture: String, - pub linux_distribution: String, } pub struct CpuCoreInfo { diff --git a/src/monitor.rs b/src/monitor.rs index 1cd0dc4..5d0468b 100644 --- a/src/monitor.rs +++ b/src/monitor.rs @@ -10,37 +10,10 @@ use std::{ time::SystemTime, }; -// Read a sysfs file to a string, trimming whitespace -fn read_sysfs_file_trimmed(path: impl AsRef) -> anyhow::Result { - fs::read_to_string(path.as_ref()) - .map(|s| s.trim().to_string()) - .map_err(|e| { - SysMonitorError::ReadError(format!("Path: {:?}, Error: {}", path.as_ref().display(), e)) - }) -} - -// Read a sysfs file and parse it to a specific type -fn read_sysfs_value(path: impl AsRef) -> anyhow::Result { - let content = read_sysfs_file_trimmed(path.as_ref())?; - content.parse::().map_err(|_| { - SysMonitorError::ParseError(format!( - "Could not parse '{}' from {:?}", - content, - path.as_ref().display() - )) - }) -} - pub fn get_system_info() -> SystemInfo { let cpu_model = get_cpu_model().unwrap_or_else(|_| "Unknown".to_string()); - let linux_distribution = get_linux_distribution().unwrap_or_else(|_| "Unknown".to_string()); - let architecture = std::env::consts::ARCH.to_string(); - SystemInfo { - cpu_model, - architecture, - linux_distribution, - } + SystemInfo { cpu_model } } pub fn get_cpu_core_info( @@ -529,45 +502,3 @@ pub fn get_cpu_model() -> anyhow::Result { "Could not find CPU model name in /proc/cpuinfo.".to_string(), )) } - -pub fn get_linux_distribution() -> anyhow::Result { - let os_release_path = Path::new("/etc/os-release"); - let content = fs::read_to_string(os_release_path).map_err(|_| { - SysMonitorError::ReadError(format!( - "Cannot read contents of {}.", - os_release_path.display() - )) - })?; - - for line in content.lines() { - if line.starts_with("PRETTY_NAME=") { - if let Some(val) = line.split('=').nth(1) { - let linux_distribution = val.trim_matches('"').to_string(); - return Ok(linux_distribution); - } - } - } - - let lsb_release_path = Path::new("/etc/lsb-release"); - let content = fs::read_to_string(lsb_release_path).map_err(|_| { - SysMonitorError::ReadError(format!( - "Cannot read contents of {}.", - lsb_release_path.display() - )) - })?; - - for line in content.lines() { - if line.starts_with("DISTRIB_DESCRIPTION=") { - if let Some(val) = line.split('=').nth(1) { - let linux_distribution = val.trim_matches('"').to_string(); - return Ok(linux_distribution); - } - } - } - - Err(SysMonitorError::ParseError(format!( - "Could not find distribution name in {} or {}.", - os_release_path.display(), - lsb_release_path.display() - ))) -}