diff --git a/Cargo.lock b/Cargo.lock index 9261c3b122..f329a97318 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -109,7 +109,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "538ecb01eb64eecd772087e5b6f7540cbc917f047727339a472dafed2185b267" dependencies = [ "async-attributes", - "async-task", + "async-task 1.3.1", "crossbeam-channel 0.4.2", "crossbeam-deque", "crossbeam-utils 0.7.2", @@ -159,6 +159,12 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "async-task" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c17772156ef2829aadc587461c7753af20b7e8db1529bc66855add962a3b35d3" + [[package]] name = "async-trait" version = "0.1.31" @@ -576,6 +582,20 @@ dependencies = [ "cfg-if", ] +[[package]] +name = "crossbeam" +version = "0.7.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69323bff1fb41c635347b8ead484a5ca6c3f11914d784170b158d8449ab07f8e" +dependencies = [ + "cfg-if", + "crossbeam-channel 0.4.2", + "crossbeam-deque", + "crossbeam-epoch", + "crossbeam-queue", + "crossbeam-utils 0.7.2", +] + [[package]] name = "crossbeam-channel" version = "0.3.9" @@ -1325,9 +1345,9 @@ checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574" [[package]] name = "heim" -version = "0.0.10" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51b8e403c0598237327b4143bdc1c7e01db0b358b5420579637e27cc117d573c" +checksum = "c39a60e3aee8ada013ddfc5d8447d6f81011dac7ddef61a3f3d34b4be982aa79" dependencies = [ "heim-common", "heim-cpu", @@ -1338,14 +1358,13 @@ dependencies = [ "heim-process", "heim-runtime", "heim-sensors", - "heim-virt", ] [[package]] name = "heim-common" -version = "0.0.10" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "144af2a423102dd4dd3e9fdd2c77c4756fb3c6c009d691628997fd5a2247719a" +checksum = "58d46c2c79530368c7a76e4808ff7263970029f38bcd544a9d43722ed0828527" dependencies = [ "cfg-if", "core-foundation 0.7.0", @@ -1356,30 +1375,34 @@ dependencies = [ "mach 0.3.2", "nix 0.17.0", "pin-utils", - "uom 0.27.0", + "uom 0.28.0", "winapi 0.3.8", ] [[package]] name = "heim-cpu" -version = "0.0.10" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8abb50616d331bd75cd7f52d56b66114a0e8813fda2201c3618a105baa2b470d" +checksum = "020d170328cadc4d6adcf549c22983a19c35068414609c276c4db607ee295693" dependencies = [ "cfg-if", + "futures 0.3.5", + "glob", "heim-common", "heim-runtime", "lazy_static 1.4.0", "libc", "mach 0.3.2", + "ntapi", + "smol", "winapi 0.3.8", ] [[package]] name = "heim-disk" -version = "0.0.10" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49e5740e687a7e1f1db597e14aff112b076f48997fe617b9b165e7c2f139d248" +checksum = "8c650cc53da13cb4027eba907bfeff7c764d801e83fd833e48b513c38ed78368" dependencies = [ "bitflags", "cfg-if", @@ -1394,25 +1417,27 @@ dependencies = [ [[package]] name = "heim-host" -version = "0.0.10" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d46019db89b0021344fd5bb8626a12cb5d9556aa8b79685ecc907b0c43e3c5f0" +checksum = "79cce3ce658bd45e510ff0a2fb5c668cbe1a7368929fd1db123741c99fd6902e" dependencies = [ "cfg-if", "heim-common", "heim-runtime", "lazy_static 1.4.0", "libc", + "log", "mach 0.3.2", + "ntapi", "platforms", "winapi 0.3.8", ] [[package]] name = "heim-memory" -version = "0.0.10" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "216b66fececba2f68a08d15b893f0c5826346b5fb4c8d5201494f8ac2347d3bf" +checksum = "edf21693fc5ebcae37997230b90876687bcf6e53d243af988a5a89215a3c2578" dependencies = [ "cfg-if", "heim-common", @@ -1425,15 +1450,14 @@ dependencies = [ [[package]] name = "heim-net" -version = "0.0.10" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "52b790922244bd5b139254a0411ea2b4e4175b3e4c261d52011a9c42535c7aa7" +checksum = "f3108a5d01cfe88042c349c93d760d2cb8d82c2131183ba6af5fc5b8a6c0a5b5" dependencies = [ "bitflags", "cfg-if", "heim-common", "heim-runtime", - "hex 0.4.0", "libc", "macaddr", "nix 0.17.0", @@ -1441,12 +1465,14 @@ dependencies = [ [[package]] name = "heim-process" -version = "0.0.10" +version = "0.1.1-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c8e29fca8becea6bc261c38230f3f45a358b7922451353dd068247a3ef059de" +checksum = "ac9b230a6f7c9d746c12a300186d6e8cb31495cdbe3cefd7a15f969327b0d323" dependencies = [ + "async-trait", "cfg-if", "darwin-libproc", + "futures 0.3.5", "heim-common", "heim-cpu", "heim-host", @@ -1458,45 +1484,33 @@ dependencies = [ "memchr", "ntapi", "ordered-float", + "smol", "winapi 0.3.8", ] [[package]] name = "heim-runtime" -version = "0.0.6" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "00bd0a5a5e4af50d5d7d9537d3ecf02dca42c26bbbd8dd76621c5116dab14f69" +checksum = "906dd26ed2eb6b9f5f0dc3dfc04caeb82785ccc05a3b3326e4c841613451acc7" dependencies = [ - "cfg-if", - "futures-channel", - "heim-common", - "lazy_static 1.4.0", - "threadpool", + "futures 0.3.5", + "futures-timer 3.0.2", + "smol", + "version-sync", ] [[package]] name = "heim-sensors" -version = "0.0.5" +version = "0.1.0-beta.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2f1250df4d79d4238261588e5aaf1de0e7853dbe632f5bd6868e394d1e730024" +checksum = "5cdae0cfeffcc728b469424c937abaa286a0d89e2a0c347c51eaddc60c029144" dependencies = [ "cfg-if", "heim-common", "heim-runtime", ] -[[package]] -name = "heim-virt" -version = "0.0.10" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e4b6ac6721ba5856659a197934ce522250a3ddd2e8646daa5660b41f1ba96457" -dependencies = [ - "cfg-if", - "heim-common", - "heim-runtime", - "raw-cpuid", -] - [[package]] name = "hermit-abi" version = "0.1.12" @@ -2890,6 +2904,18 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" +[[package]] +name = "piper" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b0deb65f46e873ba8aa7c6a8dbe3f23cb1bf59c339a81a1d56361dde4d66ac8" +dependencies = [ + "crossbeam-utils 0.7.2", + "futures-io", + "futures-sink", + "futures-util", +] + [[package]] name = "pkg-config" version = "0.3.17" @@ -3043,6 +3069,17 @@ dependencies = [ "tint", ] +[[package]] +name = "pulldown-cmark" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e142c3b8f49d2200605ee6ba0b1d757310e9e7a72afe78c36ee2ef67300ee00" +dependencies = [ + "bitflags", + "memchr", + "unicase", +] + [[package]] name = "query_interface" version = "0.3.5" @@ -3138,17 +3175,6 @@ dependencies = [ "rand_core", ] -[[package]] -name = "raw-cpuid" -version = "7.0.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b4a349ca83373cfa5d6dbb66fd76e58b2cca08da71a5f6400de0a0a6a9bceeaf" -dependencies = [ - "bitflags", - "cc", - "rustc_version", -] - [[package]] name = "rawkey" version = "0.1.2" @@ -3368,6 +3394,12 @@ dependencies = [ "winapi 0.3.8", ] +[[package]] +name = "scoped-tls-hkt" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2e9d7eaddb227e8fbaaa71136ae0e1e913ca159b86c7da82f3e8f0044ad3a63" + [[package]] name = "scopeguard" version = "1.1.0" @@ -3403,7 +3435,7 @@ version = "0.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1d7eb9ef2c18661902cc47e535f9bc51b78acd254da71d375c2f6720d9a40403" dependencies = [ - "semver-parser", + "semver-parser 0.7.0", ] [[package]] @@ -3412,6 +3444,12 @@ version = "0.7.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "388a1df253eca08550bef6c72392cfe7c30914bf41df5269b68cbd6ff8f570a3" +[[package]] +name = "semver-parser" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b46e1121e8180c12ff69a742aabc4f310542b6ccb69f1691689ac17fdf8618aa" + [[package]] name = "serde" version = "0.8.23" @@ -3614,6 +3652,25 @@ version = "1.4.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7cb5678e1615754284ec264d9bb5b4c27d2018577fd90ac0ceb578591ed5ee4" +[[package]] +name = "smol" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "686c634ad1873fffef6aed20f180eede424fbf3bb31802394c90fd7335a661b7" +dependencies = [ + "async-task 3.0.0", + "crossbeam", + "futures-io", + "futures-util", + "nix 0.17.0", + "once_cell", + "piper", + "scoped-tls-hkt", + "slab", + "socket2", + "wepoll-binding", +] + [[package]] name = "socket2" version = "0.3.12" @@ -3872,15 +3929,6 @@ dependencies = [ "lazy_static 1.4.0", ] -[[package]] -name = "threadpool" -version = "1.8.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d050e60b33d41c19108b32cea32164033a9013fe3b46cbd4457559bfbf77afaa" -dependencies = [ - "num_cpus", -] - [[package]] name = "time" version = "0.1.43" @@ -4044,9 +4092,9 @@ dependencies = [ [[package]] name = "uom" -version = "0.27.0" +version = "0.28.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "51fc04fb44bcb7806da71885872cb15d123b681e459a476ef8a0bab287bee0cd" +checksum = "627142a1043c2d460613232ce4f7e322e756636e000c0f1d1f2e779cb431358a" dependencies = [ "num-rational", "num-traits 0.2.11", @@ -4114,6 +4162,22 @@ version = "0.8.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" +[[package]] +name = "version-sync" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "382f6877399646e1b88f4b89813b4577147fa924464317378eb39c280d1e9e4c" +dependencies = [ + "itertools", + "proc-macro2", + "pulldown-cmark", + "regex", + "semver-parser 0.9.0", + "syn", + "toml 0.5.6", + "url", +] + [[package]] name = "version_check" version = "0.1.5" @@ -4238,6 +4302,25 @@ dependencies = [ "wasm-bindgen", ] +[[package]] +name = "wepoll-binding" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "374fff4ff9701ff8b6ad0d14bacd3156c44063632d8c136186ff5967d48999a7" +dependencies = [ + "bitflags", + "wepoll-sys", +] + +[[package]] +name = "wepoll-sys" +version = "2.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9082a777aed991f6769e2b654aa0cb29f1c3d615daf009829b07b66c7aff6a24" +dependencies = [ + "cc", +] + [[package]] name = "which" version = "3.1.1" diff --git a/crates/nu_plugin_ps/Cargo.toml b/crates/nu_plugin_ps/Cargo.toml index c52232e9a0..8dd370209f 100644 --- a/crates/nu_plugin_ps/Cargo.toml +++ b/crates/nu_plugin_ps/Cargo.toml @@ -19,9 +19,9 @@ futures = { version = "0.3", features = ["compat", "io-compat"] } futures-timer = "3.0.2" [dependencies.heim] -version = "0.0.10" +version = "0.1.0-beta.1" default-features = false -features = ["process", "runtime-polyfill"] +features = ["process"] [build-dependencies] nu-build = { version = "0.14.1", path = "../nu-build" } diff --git a/crates/nu_plugin_ps/src/nu/mod.rs b/crates/nu_plugin_ps/src/nu/mod.rs index 1c3854aaac..7801ecb898 100644 --- a/crates/nu_plugin_ps/src/nu/mod.rs +++ b/crates/nu_plugin_ps/src/nu/mod.rs @@ -18,7 +18,7 @@ impl Plugin for Ps { } fn begin_filter(&mut self, callinfo: CallInfo) -> Result, ShellError> { - Ok(block_on(ps(callinfo.name_tag, callinfo.args.has("full"))) + Ok(block_on(ps(callinfo.name_tag, callinfo.args.has("full")))? .into_iter() .map(ReturnSuccess::value) .collect()) diff --git a/crates/nu_plugin_ps/src/ps.rs b/crates/nu_plugin_ps/src/ps.rs index 04c060dc39..53e7da2465 100644 --- a/crates/nu_plugin_ps/src/ps.rs +++ b/crates/nu_plugin_ps/src/ps.rs @@ -3,6 +3,7 @@ use heim::process::{self as process, Process, ProcessResult}; use heim::units::{information, ratio, Ratio}; use std::usize; +use nu_errors::ShellError; use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value}; use nu_source::Tag; @@ -27,8 +28,16 @@ async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio, proc Ok((process, usage_2 - usage_1, memory)) } -pub async fn ps(tag: Tag, full: bool) -> Vec { - let mut processes = process::processes() +pub async fn ps(tag: Tag, full: bool) -> Result, ShellError> { + let processes = process::processes() + .await + .map_err(|_| { + ShellError::labeled_error( + "Unabled to get process list", + "could not load process list", + tag.span, + ) + })? .map_ok(|process| { // Note that there is no `.await` here, // as we want to pass the returned future @@ -36,6 +45,7 @@ pub async fn ps(tag: Tag, full: bool) -> Vec { usage(process) }) .try_buffer_unordered(usize::MAX); + futures::pin_mut!(processes); let mut output = vec![]; while let Some(res) = processes.next().await { @@ -80,5 +90,5 @@ pub async fn ps(tag: Tag, full: bool) -> Vec { } } - output + Ok(output) } diff --git a/crates/nu_plugin_sys/Cargo.toml b/crates/nu_plugin_sys/Cargo.toml index e4578b72fa..ca53b7dd0f 100644 --- a/crates/nu_plugin_sys/Cargo.toml +++ b/crates/nu_plugin_sys/Cargo.toml @@ -20,10 +20,10 @@ battery = "0.7.5" futures-util = "0.3.5" [dependencies.heim] -version = "0.0.10" +version = "0.1.0-beta.1" default-features = false -features = ["host", "cpu", "memory", "disk", "net", "sensors", "runtime-polyfill"] +features = ["host", "cpu", "memory", "disk", "net", "sensors"] [build-dependencies] nu-build = { version = "0.14.1", path = "../nu-build" } diff --git a/crates/nu_plugin_sys/src/sys.rs b/crates/nu_plugin_sys/src/sys.rs index 141b51c878..99116e9179 100644 --- a/crates/nu_plugin_sys/src/sys.rs +++ b/crates/nu_plugin_sys/src/sys.rs @@ -1,6 +1,7 @@ use futures_util::StreamExt; use heim::units::{frequency, information, thermodynamic_temperature, time}; use heim::{disk, host, memory, net, sensors}; +use nu_errors::ShellError; use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value}; use nu_source::Tag; use std::ffi::OsStr; @@ -77,7 +78,7 @@ async fn mem(tag: Tag) -> Value { dict.into_value() } -async fn host(tag: Tag) -> Value { +async fn host(tag: Tag) -> Result { let mut dict = TaggedDictBuilder::with_capacity(&tag, 6); let (platform_result, uptime_result) = @@ -104,7 +105,12 @@ async fn host(tag: Tag) -> Value { // Sessions // note: the heim host module has nomenclature "users" - let mut users = host::users(); + let users = host::users().await.map_err(|_| { + ShellError::labeled_error("Unabled to get users", "could not load users", tag.span) + })?; + + futures::pin_mut!(users); + let mut user_vec = vec![]; while let Some(user) = users.next().await { if let Ok(user) = user { @@ -117,12 +123,20 @@ async fn host(tag: Tag) -> Value { let user_list = UntaggedValue::Table(user_vec); dict.insert_untagged("sessions", user_list); - dict.into_value() + Ok(dict.into_value()) } -async fn disks(tag: Tag) -> Option { +async fn disks(tag: Tag) -> Result, ShellError> { let mut output = vec![]; - let mut partitions = disk::partitions_physical(); + let partitions = disk::partitions_physical().await.map_err(|_| { + ShellError::labeled_error( + "Unabled to get disk list", + "could not load disk list", + tag.span, + ) + })?; + + futures::pin_mut!(partitions); while let Some(part) = partitions.next().await { if let Ok(part) = part { @@ -162,9 +176,9 @@ async fn disks(tag: Tag) -> Option { } if !output.is_empty() { - Some(UntaggedValue::Table(output)) + Ok(Some(UntaggedValue::Table(output))) } else { - None + Ok(None) } } @@ -217,7 +231,9 @@ async fn battery(tag: Tag) -> Option { async fn temp(tag: Tag) -> Option { let mut output = vec![]; - let mut sensors = sensors::temperatures(); + let sensors = sensors::temperatures(); + + futures::pin_mut!(sensors); while let Some(sensor) = sensors.next().await { if let Ok(sensor) = sensor { @@ -260,9 +276,17 @@ async fn temp(tag: Tag) -> Option { } } -async fn net(tag: Tag) -> Option { +async fn net(tag: Tag) -> Result, ShellError> { let mut output = vec![]; - let mut io_counters = net::io_counters(); + let io_counters = net::io_counters().await.map_err(|_| { + ShellError::labeled_error( + "Unabled to get network device list", + "could not load network device list", + tag.span, + ) + })?; + + futures::pin_mut!(io_counters); while let Some(nic) = io_counters.next().await { if let Ok(nic) = nic { @@ -280,9 +304,9 @@ async fn net(tag: Tag) -> Option { } } if !output.is_empty() { - Some(UntaggedValue::Table(output)) + Ok(Some(UntaggedValue::Table(output))) } else { - None + Ok(None) } } @@ -299,18 +323,20 @@ pub async fn sysinfo(tag: Tag) -> Vec { .await; let (net, battery) = futures::future::join(net(tag.clone()), battery(tag.clone())).await; - sysinfo.insert_value("host", host); + if let Ok(host) = host { + sysinfo.insert_value("host", host); + } if let Some(cpu) = cpu { sysinfo.insert_value("cpu", cpu); } - if let Some(disks) = disks { + if let Ok(Some(disks)) = disks { sysinfo.insert_untagged("disks", disks); } sysinfo.insert_value("mem", memory); if let Some(temp) = temp { sysinfo.insert_untagged("temp", temp); } - if let Some(net) = net { + if let Ok(Some(net)) = net { sysinfo.insert_untagged("net", net); } if let Some(battery) = battery {