From a3be6affa4a928833850731424de3e92de9528ed Mon Sep 17 00:00:00 2001 From: Darren Schroeder <343840+fdncred@users.noreply.github.com> Date: Fri, 22 Jan 2021 12:39:09 -0600 Subject: [PATCH] fix some misalignment errors (#2959) --- crates/nu_plugin_sys/Cargo.toml | 10 ++++---- crates/nu_plugin_sys/src/sys.rs | 44 +++++++++++++++++++++++++-------- 2 files changed, 39 insertions(+), 15 deletions(-) diff --git a/crates/nu_plugin_sys/Cargo.toml b/crates/nu_plugin_sys/Cargo.toml index 6f0506e8cd..556449a5c5 100644 --- a/crates/nu_plugin_sys/Cargo.toml +++ b/crates/nu_plugin_sys/Cargo.toml @@ -10,12 +10,12 @@ version = "0.25.2" doctest = false [dependencies] -nu-errors = {path = "../nu-errors", version = "0.25.2"} -nu-plugin = {path = "../nu-plugin", version = "0.25.2"} -nu-protocol = {path = "../nu-protocol", version = "0.25.2"} -nu-source = {path = "../nu-source", version = "0.25.2"} +nu-errors = { path = "../nu-errors", version = "0.25.2" } +nu-plugin = { path = "../nu-plugin", version = "0.25.2" } +nu-protocol = { path = "../nu-protocol", version = "0.25.2" } +nu-source = { path = "../nu-source", version = "0.25.2" } -futures = {version = "0.3.5", features = ["compat", "io-compat"]} +futures = { version = "0.3.5", features = ["compat", "io-compat"] } futures-util = "0.3.5" num-bigint = "0.3.0" sysinfo = "0.15.9" diff --git a/crates/nu_plugin_sys/src/sys.rs b/crates/nu_plugin_sys/src/sys.rs index ccc9077eae..e971a8d184 100644 --- a/crates/nu_plugin_sys/src/sys.rs +++ b/crates/nu_plugin_sys/src/sys.rs @@ -19,11 +19,15 @@ pub fn disks(sys: &mut System, tag: Tag) -> Option { let mut dict = TaggedDictBuilder::new(&tag); dict.insert_untagged( "device", - UntaggedValue::string(disk.get_name().to_string_lossy()), + UntaggedValue::string(trim_cstyle_null( + disk.get_name().to_string_lossy().to_string(), + )), ); dict.insert_untagged( "type", - UntaggedValue::string(String::from_utf8_lossy(disk.get_file_system())), + UntaggedValue::string(trim_cstyle_null( + String::from_utf8_lossy(disk.get_file_system()).to_string(), + )), ); dict.insert_untagged("mount", UntaggedValue::filepath(disk.get_mount_point())); dict.insert_untagged("total", UntaggedValue::filesize(disk.get_total_space())); @@ -43,7 +47,10 @@ pub fn net(sys: &mut System, tag: Tag) -> Option { let mut output = vec![]; for (iface, data) in sys.get_networks() { let mut dict = TaggedDictBuilder::new(&tag); - dict.insert_untagged("name", UntaggedValue::string(iface)); + dict.insert_untagged( + "name", + UntaggedValue::string(trim_cstyle_null(iface.to_string())), + ); dict.insert_untagged( "sent", UntaggedValue::filesize(data.get_total_transmitted()), @@ -65,8 +72,14 @@ pub fn cpu(sys: &mut System, tag: Tag) -> Option { let mut output = vec![]; for cpu in sys.get_processors() { let mut dict = TaggedDictBuilder::new(&tag); - dict.insert_untagged("name", UntaggedValue::string(cpu.get_name())); - dict.insert_untagged("brand", UntaggedValue::string(cpu.get_brand())); + dict.insert_untagged( + "name", + UntaggedValue::string(trim_cstyle_null(cpu.get_name().to_string())), + ); + dict.insert_untagged( + "brand", + UntaggedValue::string(trim_cstyle_null(cpu.get_brand().to_string())), + ); dict.insert_untagged("freq", UntaggedValue::int(cpu.get_frequency())); output.push(dict.into_value()); @@ -100,13 +113,16 @@ pub fn host(sys: &mut System, tag: Tag) -> Option { let mut dict = TaggedDictBuilder::new(&tag); if let Some(name) = sys.get_name() { - dict.insert_untagged("name", UntaggedValue::string(name)); + dict.insert_untagged("name", UntaggedValue::string(trim_cstyle_null(name))); } if let Some(version) = sys.get_version() { - dict.insert_untagged("version", UntaggedValue::string(version)); + dict.insert_untagged("version", UntaggedValue::string(trim_cstyle_null(version))); } if let Some(hostname) = sys.get_host_name() { - dict.insert_untagged("hostname", UntaggedValue::string(hostname)); + dict.insert_untagged( + "hostname", + UntaggedValue::string(trim_cstyle_null(hostname)), + ); } dict.insert_untagged( "uptime", @@ -116,11 +132,15 @@ pub fn host(sys: &mut System, tag: Tag) -> Option { let mut users = vec![]; for user in sys.get_users() { let mut user_dict = TaggedDictBuilder::new(&tag); - user_dict.insert_untagged("name", UntaggedValue::string(user.get_name())); + user_dict.insert_untagged( + "name", + UntaggedValue::string(trim_cstyle_null(user.get_name().to_string())), + ); let mut groups = vec![]; for group in user.get_groups() { - groups.push(UntaggedValue::string(group).into_value(&tag)); + groups + .push(UntaggedValue::string(trim_cstyle_null(group.to_string())).into_value(&tag)); } user_dict.insert_untagged("groups", UntaggedValue::Table(groups)); @@ -193,3 +213,7 @@ pub async fn sysinfo(tag: Tag) -> Vec { vec![sysinfo.into_value()] } + +pub fn trim_cstyle_null(s: String) -> String { + s.trim_matches(char::from(0)).to_string() +}