diff --git a/Cargo.lock b/Cargo.lock index 1d7f9272438..529e1ec358e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1712,9 +1712,9 @@ checksum = "6ac9a59f73473f1b8d852421e59e64809f025994837ef743615c6d0c5b305160" [[package]] name = "platform-info" -version = "1.0.2" +version = "2.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4e7c23cfae725ae06d9e43010153fa77bdfa8c827bf08fe4beeb2a3514e6be12" +checksum = "827dc4f7a81331d48c8abf11b5ac18673b390d33e9632327e286d940289aefab" dependencies = [ "libc", "winapi", diff --git a/Cargo.toml b/Cargo.toml index 595be01f46c..09926770923 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -304,7 +304,7 @@ onig = { version = "~6.4", default-features = false } ouroboros = "0.15.6" phf = "0.11.1" phf_codegen = "0.11.1" -platform-info = "1.0.2" +platform-info = "2.0.1" quick-error = "2.0.1" rand = { version = "0.8", features = ["small_rng"] } rand_core = "0.6" diff --git a/src/uu/arch/src/arch.rs b/src/uu/arch/src/arch.rs index a2208d8b031..61131caa944 100644 --- a/src/uu/arch/src/arch.rs +++ b/src/uu/arch/src/arch.rs @@ -9,7 +9,7 @@ use platform_info::*; use clap::{crate_version, Command}; -use uucore::error::{FromIo, UResult}; +use uucore::error::{UResult, USimpleError}; use uucore::{help_about, help_section}; static ABOUT: &str = help_about!("arch.md"); @@ -19,8 +19,12 @@ static SUMMARY: &str = help_section!("after help", "arch.md"); pub fn uumain(args: impl uucore::Args) -> UResult<()> { uu_app().try_get_matches_from(args)?; - let uts = PlatformInfo::new().map_err_context(|| "cannot get system name".to_string())?; - println!("{}", uts.machine().trim()); + let uts = match PlatformInfo::new() { + Ok(x) => x, + Err(_e) => return Err(USimpleError::new(1, "cannot get system name")), + }; + + println!("{}", uts.machine().to_string_lossy().trim()); Ok(()) } diff --git a/src/uu/uname/src/uname.rs b/src/uu/uname/src/uname.rs index df744dd8509..8b867923454 100644 --- a/src/uu/uname/src/uname.rs +++ b/src/uu/uname/src/uname.rs @@ -13,7 +13,7 @@ use clap::{crate_version, Arg, ArgAction, Command}; use platform_info::*; use uucore::{ - error::{FromIo, UResult}, + error::{UResult, USimpleError}, format_usage, help_about, help_usage, }; @@ -36,8 +36,8 @@ pub mod options { pub fn uumain(args: impl uucore::Args) -> UResult<()> { let matches = uu_app().try_get_matches_from(args)?; - let uname = - PlatformInfo::new().map_err_context(|| "failed to create PlatformInfo".to_string())?; + let uname = PlatformInfo::new().map_err(|_e| USimpleError::new(1, "cannot get system name"))?; + let mut output = String::new(); let all = matches.get_flag(options::ALL); @@ -61,33 +61,32 @@ pub fn uumain(args: impl uucore::Args) -> UResult<()> { || hardware_platform); if kernel_name || all || none { - output.push_str(&uname.sysname()); + output.push_str(&uname.sysname().to_string_lossy()); output.push(' '); } if nodename || all { - // maint: [2023-01-14; rivy] remove `.trim_end_matches('\0')` when platform-info nodename-NUL bug is fixed (see GH:uutils/platform-info/issues/32) - output.push_str(uname.nodename().trim_end_matches('\0')); + output.push_str(&uname.nodename().to_string_lossy()); output.push(' '); } if kernel_release || all { - output.push_str(&uname.release()); + output.push_str(&uname.release().to_string_lossy()); output.push(' '); } if kernel_version || all { - output.push_str(&uname.version()); + output.push_str(&uname.version().to_string_lossy()); output.push(' '); } if machine || all { - output.push_str(&uname.machine()); + output.push_str(&uname.machine().to_string_lossy()); output.push(' '); } if os || all { - output.push_str(&uname.osname()); + output.push_str(&uname.osname().to_string_lossy()); output.push(' '); }