Skip to content

Commit 9a5df07

Browse files
committed
exit when the dmi file is not found
1 parent 62d4c22 commit 9a5df07

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

src/dmi.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use std::{
66
fmt::Display,
77
fs::File,
88
io::{BufRead, BufReader, Read},
9+
path::Path,
910
};
1011

1112
use anyhow::{Result, bail};
@@ -82,6 +83,20 @@ impl DMI {
8283
let mut system: Option<System> = None;
8384
let mut baseboard: Option<Baseboard> = None;
8485

86+
let dmi_file_path = Path::new("/sys/firmware/dmi/tables/DMI");
87+
88+
match dmi_file_path.try_exists() {
89+
Ok(true) => {}
90+
Ok(false) => {
91+
eprintln!("Can not find {} file", dmi_file_path.to_string_lossy());
92+
std::process::exit(1);
93+
}
94+
Err(_) => {
95+
eprintln!("e");
96+
std::process::exit(1);
97+
}
98+
}
99+
85100
let mem_file = File::open("/sys/firmware/dmi/tables/DMI")?;
86101
let mut file = BufReader::new(mem_file);
87102

0 commit comments

Comments
 (0)