Skip to content

Commit

Permalink
Use result type instead of unwrapping value
Browse files Browse the repository at this point in the history
  • Loading branch information
martintc committed Apr 11, 2022
1 parent e4b685e commit d867959
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions os_info/src/freebsd/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,19 @@ fn get_os() -> Type {
.output()
.expect("Failed to get OS");

match str::from_utf8(&os.stdout).unwrap() {
"FreeBSD\n" => {
match str::from_utf8(&os.stdout).trim() {
Ok("FreeBSD") => {
let check_hardening = Command::new("sysctl")
.arg("hardening.version")
.output()
.expect("Failed to check if is hardened");
match str::from_utf8(&check_hardening.stderr).unwrap() {
"" => return Type::HardenedBSD,
_ => return Type::FreeBSD,
match str::from_utf8(&check_hardening.stderr).trim() {
Ok("0") => return Type::HardenedBSD,
Err(_) => return Type::FreeBSD,
}
}
"MidnightBSD\n" => Type::MidnightBSD,
_ => Type::Unknown,
Ok("MidnightBSD") => Type::MidnightBSD,
Err(_) => Type::Unknown,
}
}

Expand Down

0 comments on commit d867959

Please sign in to comment.