diff --git a/src/deprecated/mod.rs b/src/deprecated/mod.rs deleted file mode 100644 index b47eb6a..0000000 --- a/src/deprecated/mod.rs +++ /dev/null @@ -1,17 +0,0 @@ -use std::{collections::HashMap, process::Command}; - -/// This module contains functions that gathers CPU brand information. -pub mod cpu_brand; -/// This module contains disk related functions. -pub mod disks; - -pub mod helper; - -fn get_all_disks() -> Vec> { - disks::get_all_disks() -} - - -fn get_cpu_brand() -> Option { - cpu_brand::get_name() -} diff --git a/src/deprecated/cpu_brand.rs b/src/legacy/cpu_brand.rs similarity index 96% rename from src/deprecated/cpu_brand.rs rename to src/legacy/cpu_brand.rs index 1af76a2..9814381 100644 --- a/src/deprecated/cpu_brand.rs +++ b/src/legacy/cpu_brand.rs @@ -1,7 +1,7 @@ use std::fs::File; use std::io::{self, BufRead}; -use crate::deprecated::helper::run_command; +use crate::legacy::helper::run_command; /// Function to get processor information. /// @@ -81,7 +81,7 @@ fn get_processor_info_windows(lib_path: &str) -> Result { pub fn get_name() -> Option { let operating_system = std::env::consts::OS; let result = match operating_system { - "darwin" => get_processor_info_darwin("/usr/sbin/sysctl"), + "macos" => get_processor_info_darwin("/usr/sbin/sysctl"), "linux" => get_processor_info_linux("/proc/cpuinfo"), "windows" => get_processor_info_windows("C:\\Windows\\System32\\wbem\\wmic.exe"), _ => { diff --git a/src/deprecated/disks.rs b/src/legacy/disks.rs similarity index 99% rename from src/deprecated/disks.rs rename to src/legacy/disks.rs index 2616846..5a00223 100644 --- a/src/deprecated/disks.rs +++ b/src/legacy/disks.rs @@ -3,7 +3,7 @@ use std::str; use regex::Regex; use serde_json::Value; -use crate::deprecated::helper::{run_command, size_converter}; +use crate::legacy::helper::{run_command, size_converter}; /// Function to parse size string for Linux. /// diff --git a/src/deprecated/helper.rs b/src/legacy/helper.rs similarity index 100% rename from src/deprecated/helper.rs rename to src/legacy/helper.rs diff --git a/src/legacy/mod.rs b/src/legacy/mod.rs new file mode 100644 index 0000000..bc73065 --- /dev/null +++ b/src/legacy/mod.rs @@ -0,0 +1,6 @@ +/// This module contains functions that gathers CPU brand information. +pub mod cpu_brand; +/// This module contains disk related functions. +pub mod disks; +/// Helper for legacy functions. +pub mod helper; diff --git a/src/lib.rs b/src/lib.rs index f818483..675309a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -18,8 +18,8 @@ mod squire; mod templates; /// Module for functions related to system resources. mod resources; -/// Module for deprecated (but still useful for reference) functions -mod deprecated; +/// Module for legacy (but still useful for reference) functions +mod legacy; /// Contains entrypoint and initializer settings to trigger the asynchronous `HTTPServer` /// diff --git a/src/resources/info.rs b/src/resources/info.rs index 2184fa3..18b5a7b 100644 --- a/src/resources/info.rs +++ b/src/resources/info.rs @@ -1,4 +1,4 @@ -use crate::{resources, squire}; +use crate::{resources, squire, legacy}; use chrono::Utc; use std::collections::HashMap; use std::collections::HashSet; @@ -56,8 +56,13 @@ fn get_cpu_brand(sys: &System) -> String { cpu_brands.insert(cpu.brand().to_string()); } if cpu_brands.is_empty() { - log::error!("Unable to get brand information for all {} CPUs", cpus.len()); - return "Unknown".to_string() + log::warn!("Unable to get brand information for all {} CPUs", cpus.len()); + let legacy_cpu_brand_name = legacy::cpu_brand::get_name(); + return if legacy_cpu_brand_name.is_some() { + legacy_cpu_brand_name.unwrap() + } else { + "Unknown".to_string() + } } let mut cpu_brand_list: Vec = cpu_brands.into_iter().collect(); cpu_brand_list.sort_by_key(|brand| brand.len()); diff --git a/src/routes/monitor.rs b/src/routes/monitor.rs index 6756dea..7db62a7 100644 --- a/src/routes/monitor.rs +++ b/src/routes/monitor.rs @@ -1,9 +1,9 @@ -use crate::{constant, resources, routes, squire}; +use crate::{constant, legacy, resources, routes, squire}; use actix_web::http::StatusCode; use actix_web::{web, HttpRequest, HttpResponse}; use fernet::Fernet; -use sysinfo::Disks; use std::sync::Arc; +use sysinfo::Disks; /// Handles the monitor endpoint and rendering the appropriate HTML page. /// @@ -39,7 +39,13 @@ pub async fn monitor(request: HttpRequest, let disks = Disks::new_with_refreshed_list(); let sys_info_map = resources::info::get_sys_info(&disks); - let sys_info_disks = resources::info::get_disks(&disks); + let legacy_disk_info = legacy::disks::get_all_disks(); + + let sys_info_disks = if legacy_disk_info.is_empty() { + resources::info::get_disks(&disks) + } else { + legacy_disk_info + }; let sys_info_network = resources::network::get_network_info().await;