Skip to content

Commit

Permalink
Fix broken non-utf8 support for some platform / function combinations (
Browse files Browse the repository at this point in the history
  • Loading branch information
AldaronLau authored Aug 17, 2023
1 parent 188c446 commit 1c076a5
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions src/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,8 +300,7 @@ pub(crate) fn devicename_os() -> OsString {

#[cfg(not(any(target_os = "macos", target_os = "illumos")))]
pub(crate) fn devicename() -> String {
if let Ok(program) = std::fs::read_to_string("/etc/machine-info") {
let program = program.into_bytes();
if let Ok(program) = std::fs::read("/etc/machine-info") {
let distro = String::from_utf8_lossy(&program);

for i in distro.split('\n') {
Expand Down Expand Up @@ -338,8 +337,7 @@ pub(crate) fn devicename_os() -> OsString {

#[cfg(target_os = "illumos")]
pub(crate) fn devicename() -> String {
if let Ok(program) = std::fs::read_to_string("/etc/nodename") {
let program = program.into_bytes();
if let Ok(program) = std::fs::read("/etc/nodename") {
let mut nodename = String::from_utf8_lossy(&program).to_string();

// Remove the trailing newline
Expand Down Expand Up @@ -444,9 +442,7 @@ pub(crate) fn distro_os() -> Option<OsString> {

#[cfg(not(target_os = "macos"))]
pub(crate) fn distro() -> Option<String> {
let program = std::fs::read_to_string("/etc/os-release")
.ok()?
.into_bytes();
let program = std::fs::read("/etc/os-release").ok()?;
let distro = String::from_utf8_lossy(&program);
let mut fallback = None;

Expand Down

0 comments on commit 1c076a5

Please sign in to comment.