diff --git a/rust/Cargo.Bazel.lock b/rust/Cargo.Bazel.lock index c6d7a3aa62c11..39619b74b7da2 100644 --- a/rust/Cargo.Bazel.lock +++ b/rust/Cargo.Bazel.lock @@ -1,5 +1,5 @@ { - "checksum": "14dbf17d9e872e55d0e978b15ce60660603017dfddf7a924539a1085d1255e3f", + "checksum": "2e41cb73375f93664a33a387f57c14d87cccc43361197a1b4f325e2bc05f6954", "crates": { "addr2line 0.21.0": { "name": "addr2line", @@ -3713,6 +3713,52 @@ ], "license_file": "LICENSE" }, + "either 1.12.0": { + "name": "either", + "version": "1.12.0", + "package_url": "https://github.com/rayon-rs/either", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/either/1.12.0/download", + "sha256": "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + } + }, + "targets": [ + { + "Library": { + "crate_name": "either", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": false, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "either", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "crate_features": { + "common": [ + "default", + "use_std" + ], + "selects": {} + }, + "edition": "2018", + "version": "1.12.0" + }, + "license": "MIT OR Apache-2.0", + "license_ids": [ + "Apache-2.0", + "MIT" + ], + "license_file": "LICENSE-APACHE" + }, "encoding_rs 0.8.34": { "name": "encoding_rs", "version": "0.8.34", @@ -5814,6 +5860,56 @@ ], "license_file": "LICENSE-APACHE" }, + "home 0.5.9": { + "name": "home", + "version": "0.5.9", + "package_url": "https://github.com/rust-lang/cargo", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/home/0.5.9/download", + "sha256": "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" + } + }, + "targets": [ + { + "Library": { + "crate_name": "home", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": false, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "home", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "deps": { + "common": [], + "selects": { + "cfg(windows)": [ + { + "id": "windows-sys 0.52.0", + "target": "windows_sys" + } + ] + } + }, + "edition": "2021", + "version": "0.5.9" + }, + "license": "MIT OR Apache-2.0", + "license_ids": [ + "Apache-2.0", + "MIT" + ], + "license_file": "LICENSE-APACHE" + }, "http 0.2.12": { "name": "http", "version": "0.2.12", @@ -11581,10 +11677,6 @@ "id": "infer 0.15.0", "target": "infer" }, - { - "id": "is_executable 1.0.1", - "target": "is_executable" - }, { "id": "log 0.4.21", "target": "log" @@ -11629,6 +11721,10 @@ "id": "walkdir 2.5.0", "target": "walkdir" }, + { + "id": "which 6.0.1", + "target": "which" + }, { "id": "zip 1.3.0", "target": "zip" @@ -11642,6 +11738,10 @@ "id": "assert_cmd 2.0.14", "target": "assert_cmd" }, + { + "id": "is_executable 1.0.1", + "target": "is_executable" + }, { "id": "rstest 0.19.0", "target": "rstest" @@ -16115,6 +16215,72 @@ ], "license_file": "LICENSE" }, + "which 6.0.1": { + "name": "which", + "version": "6.0.1", + "package_url": "https://github.com/harryfei/which-rs.git", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/which/6.0.1/download", + "sha256": "8211e4f58a2b2805adfbefbc07bab82958fc91e3836339b1ab7ae32465dce0d7" + } + }, + "targets": [ + { + "Library": { + "crate_name": "which", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": false, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "which", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "deps": { + "common": [ + { + "id": "either 1.12.0", + "target": "either" + } + ], + "selects": { + "cfg(any(unix, target_os = \"wasi\", target_os = \"redox\"))": [ + { + "id": "rustix 0.38.34", + "target": "rustix" + } + ], + "cfg(any(windows, unix, target_os = \"redox\"))": [ + { + "id": "home 0.5.9", + "target": "home" + } + ], + "cfg(windows)": [ + { + "id": "winsafe 0.0.19", + "target": "winsafe" + } + ] + } + }, + "edition": "2021", + "version": "6.0.1" + }, + "license": "MIT", + "license_ids": [ + "MIT" + ], + "license_file": "LICENSE.txt" + }, "winapi 0.3.9": { "name": "winapi", "version": "0.3.9", @@ -16539,11 +16705,14 @@ "Win32_Storage", "Win32_Storage_FileSystem", "Win32_System", + "Win32_System_Com", "Win32_System_Console", "Win32_System_IO", "Win32_System_SystemInformation", "Win32_System_Threading", "Win32_System_WindowsProgramming", + "Win32_UI", + "Win32_UI_Shell", "default" ], "selects": {} @@ -17868,6 +18037,50 @@ ], "license_file": "LICENSE" }, + "winsafe 0.0.19": { + "name": "winsafe", + "version": "0.0.19", + "package_url": "https://github.com/rodrigocfd/winsafe", + "repository": { + "Http": { + "url": "https://static.crates.io/crates/winsafe/0.0.19/download", + "sha256": "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + } + }, + "targets": [ + { + "Library": { + "crate_name": "winsafe", + "crate_root": "src/lib.rs", + "srcs": { + "allow_empty": false, + "include": [ + "**/*.rs" + ] + } + } + } + ], + "library_target_name": "winsafe", + "common_attrs": { + "compile_data_glob": [ + "**" + ], + "crate_features": { + "common": [ + "kernel" + ], + "selects": {} + }, + "edition": "2021", + "version": "0.0.19" + }, + "license": "MIT", + "license_ids": [ + "MIT" + ], + "license_file": "LICENSE.md" + }, "x509-certificate 0.23.1": { "name": "x509-certificate", "version": "0.23.1", @@ -18837,6 +19050,62 @@ "x86_64-unknown-linux-gnu", "x86_64-unknown-nixos-gnu" ], + "cfg(any(unix, target_os = \"wasi\", target_os = \"redox\"))": [ + "aarch64-apple-darwin", + "aarch64-apple-ios", + "aarch64-apple-ios-sim", + "aarch64-fuchsia", + "aarch64-linux-android", + "aarch64-unknown-linux-gnu", + "aarch64-unknown-nixos-gnu", + "aarch64-unknown-nto-qnx710", + "arm-unknown-linux-gnueabi", + "armv7-linux-androideabi", + "armv7-unknown-linux-gnueabi", + "i686-apple-darwin", + "i686-linux-android", + "i686-unknown-freebsd", + "i686-unknown-linux-gnu", + "powerpc-unknown-linux-gnu", + "s390x-unknown-linux-gnu", + "wasm32-wasi", + "x86_64-apple-darwin", + "x86_64-apple-ios", + "x86_64-fuchsia", + "x86_64-linux-android", + "x86_64-unknown-freebsd", + "x86_64-unknown-linux-gnu", + "x86_64-unknown-nixos-gnu" + ], + "cfg(any(windows, unix, target_os = \"redox\"))": [ + "aarch64-apple-darwin", + "aarch64-apple-ios", + "aarch64-apple-ios-sim", + "aarch64-fuchsia", + "aarch64-linux-android", + "aarch64-pc-windows-msvc", + "aarch64-unknown-linux-gnu", + "aarch64-unknown-nixos-gnu", + "aarch64-unknown-nto-qnx710", + "arm-unknown-linux-gnueabi", + "armv7-linux-androideabi", + "armv7-unknown-linux-gnueabi", + "i686-apple-darwin", + "i686-linux-android", + "i686-pc-windows-msvc", + "i686-unknown-freebsd", + "i686-unknown-linux-gnu", + "powerpc-unknown-linux-gnu", + "s390x-unknown-linux-gnu", + "x86_64-apple-darwin", + "x86_64-apple-ios", + "x86_64-fuchsia", + "x86_64-linux-android", + "x86_64-pc-windows-msvc", + "x86_64-unknown-freebsd", + "x86_64-unknown-linux-gnu", + "x86_64-unknown-nixos-gnu" + ], "cfg(fuzzing)": [], "cfg(not(all(windows, target_env = \"msvc\", not(target_vendor = \"uwp\"))))": [ "aarch64-apple-darwin", @@ -19124,7 +19393,6 @@ "exitcode 1.1.2", "flate2 1.0.30", "infer 0.15.0", - "is_executable 1.0.1", "log 0.4.21", "regex 1.10.4", "reqwest 0.12.4", @@ -19136,10 +19404,12 @@ "tokio 1.37.0", "toml 0.8.13", "walkdir 2.5.0", + "which 6.0.1", "zip 1.3.0" ], "direct_dev_deps": [ "assert_cmd 2.0.14", + "is_executable 1.0.1", "rstest 0.19.0" ] } diff --git a/rust/Cargo.lock b/rust/Cargo.lock index efd1b05f8d3ff..6921db2265fb4 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -606,6 +606,12 @@ version = "0.3.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "fea41bba32d969b513997752735605054bc0dfa92b4c56bf1189f2e174be7a10" +[[package]] +name = "either" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3dca9240753cf90908d7e4aac30f630662b02aebaa1b58a3cadabdb23385b58b" + [[package]] name = "encoding_rs" version = "0.8.34" @@ -892,6 +898,15 @@ version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" +[[package]] +name = "home" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" +dependencies = [ + "windows-sys 0.52.0", +] + [[package]] name = "http" version = "0.2.12" @@ -1828,6 +1843,7 @@ dependencies = [ "tokio", "toml", "walkdir", + "which", "zip", ] @@ -2483,6 +2499,18 @@ dependencies = [ "rustls-pki-types", ] +[[package]] +name = "which" +version = "6.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8211e4f58a2b2805adfbefbc07bab82958fc91e3836339b1ab7ae32465dce0d7" +dependencies = [ + "either", + "home", + "rustix", + "winsafe", +] + [[package]] name = "winapi" version = "0.3.9" @@ -2691,6 +2719,12 @@ dependencies = [ "windows-sys 0.48.0", ] +[[package]] +name = "winsafe" +version = "0.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d135d17ab770252ad95e9a872d365cf3090e3be864a34ab46f48555993efc904" + [[package]] name = "x509-certificate" version = "0.23.1" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 02affb86181b4..06b39dd64cc0d 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -27,7 +27,6 @@ flate2 = "1.0.30" tar = "0.4.40" infer = "0.15.0" exitcode = "1.1.2" -is_executable = "1.0.1" toml = "0.8.13" bzip2 = "0.4.4" sevenz-rust = "0.6.0" @@ -35,10 +34,12 @@ walkdir = "2.5.0" debpkg = "0.6.0" anyhow = { version = "1.0.84", default-features = false, features = ["backtrace", "std"] } apple-flat-package = "0.18.0" +which = "6.0.1" [dev-dependencies] assert_cmd = "2.0.14" rstest = "0.19.0" +is_executable = "1.0.1" [profile.release] opt-level = 'z' # Optimize for size diff --git a/rust/src/lib.rs b/rust/src/lib.rs index 95dcad9906d22..b01a7e4822618 100644 --- a/rust/src/lib.rs +++ b/rust/src/lib.rs @@ -37,12 +37,11 @@ use crate::metadata::{ use crate::safari::{SafariManager, SAFARIDRIVER_NAME, SAFARI_NAME}; use crate::safaritp::{SafariTPManager, SAFARITP_NAMES}; use crate::shell::{ - run_shell_command, run_shell_command_by_os, run_shell_command_with_log, split_lines, Command, + run_shell_command, run_shell_command_by_os, run_shell_command_with_log, Command, }; use crate::stats::{send_stats_to_plausible, Props}; use anyhow::anyhow; use anyhow::Error; -use is_executable::IsExecutable; use reqwest::{Client, Proxy}; use std::collections::HashMap; use std::path::{Path, PathBuf}; @@ -50,6 +49,7 @@ use std::sync::mpsc::{Receiver, Sender}; use std::time::Duration; use std::{env, fs, thread}; use walkdir::DirEntry; +use which::which; pub mod chrome; pub mod config; @@ -98,8 +98,6 @@ pub const ARCH_X86: &str = "x86"; pub const ARCH_AMD64: &str = "amd64"; pub const ARCH_ARM64: &str = "arm64"; pub const ENV_PROCESSOR_ARCHITECTURE: &str = "PROCESSOR_ARCHITECTURE"; -pub const WHERE_COMMAND: &str = "where {}"; -pub const WHICH_COMMAND: &str = "which {}"; pub const TTL_SEC: u64 = 3600; pub const UNAME_COMMAND: &str = "uname -{}"; pub const ESCAPE_COMMAND: &str = "printf %q \"{}\""; @@ -594,32 +592,10 @@ pub trait SeleniumManager { } fn execute_which_in_shell(&self, arg: &str) -> Option { - let which_or_where = if WINDOWS.is(self.get_os()) { - WHERE_COMMAND - } else { - WHICH_COMMAND - }; - let which_command = Command::new_single(format_one_arg(which_or_where, arg)); - let path = match run_shell_command_by_os(self.get_os(), which_command) { - Ok(path) => { - let path_vector = split_lines(path.as_str()); - if path_vector.len() == 1 { - self.get_first_in_vector(path_vector) - } else { - let exec_paths: Vec<&str> = path_vector - .into_iter() - .filter(|p| Path::new(p).is_executable()) - .collect(); - if exec_paths.is_empty() { - None - } else { - self.get_first_in_vector(exec_paths) - } - } - } + match which(arg) { + Ok(path) => Some(path_to_string(&path)), Err(_) => None, - }; - path + } } fn get_first_in_vector(&self, vector: Vec<&str>) -> Option { diff --git a/rust/src/shell.rs b/rust/src/shell.rs index 1c50d88cb77e3..203ba693a8924 100644 --- a/rust/src/shell.rs +++ b/rust/src/shell.rs @@ -96,10 +96,7 @@ pub fn run_shell_command(shell: &str, flag: &str, command: Command) -> Result &str {