diff --git a/Cargo.lock b/Cargo.lock index ee990ef92ac..20c331e559d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -517,26 +517,6 @@ dependencies = [ "windows-sys 0.61.2", ] -[[package]] -name = "const-random" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" -dependencies = [ - "const-random-macro", -] - -[[package]] -name = "const-random-macro" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" -dependencies = [ - "getrandom 0.2.17", - "once_cell", - "tiny-keccak", -] - [[package]] name = "constant_time_eq" version = "0.4.2" @@ -972,15 +952,6 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "dlv-list" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" -dependencies = [ - "const-random", -] - [[package]] name = "dns-lookup" version = "4.0.1" @@ -1275,12 +1246,6 @@ dependencies = [ "zerocopy 0.8.56", ] -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hashbrown" version = "0.16.1" @@ -2234,16 +2199,6 @@ dependencies = [ "vcpkg", ] -[[package]] -name = "ordered-multimap" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" -dependencies = [ - "dlv-list", - "hashbrown 0.14.5", -] - [[package]] name = "os_display" version = "0.1.4" @@ -2660,16 +2615,6 @@ dependencies = [ "syn 2.0.119", ] -[[package]] -name = "rust-ini" -version = "0.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "796e8d2b6696392a43bea58116b667fb4c29727dc5abd27d6acf338bb4f688c7" -dependencies = [ - "cfg-if", - "ordered-multimap", -] - [[package]] name = "rustc-hash" version = "2.1.3" @@ -3117,15 +3062,6 @@ dependencies = [ "time-core", ] -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - [[package]] name = "tinystr" version = "0.8.4" @@ -3592,7 +3528,6 @@ dependencies = [ "clap", "fluent", "nix", - "rust-ini", "thiserror 2.0.20", "uucore", ] diff --git a/Cargo.toml b/Cargo.toml index c6792682728..621d038d17c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -395,7 +395,6 @@ rlimit = "0.11.0" rstest = "0.27.0" rstest_reuse = "0.7.0" rustc-hash = "2.1.1" -rust-ini = "0.21.0" rustix = { version = "1.1.4", default-features = false } self_cell = "1.0.4" selinux = "0.6" diff --git a/docs/src/extensions.md b/docs/src/extensions.md index ffbe099bee1..489886394e2 100644 --- a/docs/src/extensions.md +++ b/docs/src/extensions.md @@ -50,10 +50,6 @@ GNU `env` allows the empty string to be used as an environment variable name. This is unsupported by uutils, which will show a warning for any such assignment. - `env` has an additional `-f`/`--file` flag that can -parse `.env` files and set variables accordingly. This feature is adopted from `dotenv` style -packages. - ## `expand` `expand` offers the `-U`/`--no-utf8` option to interpret input files as 8-bit ASCII instead of UTF-8. diff --git a/fuzz/Cargo.lock b/fuzz/Cargo.lock index 10168046da6..1049b2acd38 100644 --- a/fuzz/Cargo.lock +++ b/fuzz/Cargo.lock @@ -309,26 +309,6 @@ dependencies = [ "windows-sys", ] -[[package]] -name = "const-random" -version = "0.1.18" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "87e00182fe74b066627d63b85fd550ac2998d4b0bd86bfed477a0ae4c7c71359" -dependencies = [ - "const-random-macro", -] - -[[package]] -name = "const-random-macro" -version = "0.1.16" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f9d839f2a20b0aee515dc581a6172f2321f96cab76c1a38a4c584a194955390e" -dependencies = [ - "getrandom 0.2.17", - "once_cell", - "tiny-keccak", -] - [[package]] name = "constant_time_eq" version = "0.4.2" @@ -420,12 +400,6 @@ version = "0.8.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "61803da095bee82a81bb1a452ecc25d3b2f1416d1897eb86430c6159ef717c17" -[[package]] -name = "crunchy" -version = "0.2.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "460fbee9c2c2f33933d720630a6a0bac33ba7053db5344fac858d4b8952d77d5" - [[package]] name = "crypto-common" version = "0.1.7" @@ -555,15 +529,6 @@ dependencies = [ "syn 3.0.4", ] -[[package]] -name = "dlv-list" -version = "0.5.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "442039f5147480ba31067cb00ada1adae6892028e40e45fc5de7b7df6dcc1b5f" -dependencies = [ - "const-random", -] - [[package]] name = "dunce" version = "1.0.5" @@ -722,17 +687,6 @@ dependencies = [ "version_check", ] -[[package]] -name = "getrandom" -version = "0.2.17" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0" -dependencies = [ - "cfg-if", - "libc", - "wasi", -] - [[package]] name = "getrandom" version = "0.4.3" @@ -751,12 +705,6 @@ version = "0.3.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" -[[package]] -name = "hashbrown" -version = "0.14.5" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1" - [[package]] name = "hex" version = "0.4.3" @@ -1185,7 +1133,7 @@ version = "0.1.35" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1c00acbd29eabad4a2392fa0e921c874934dbbf4194312ad20f04a0ed67a3cb3" dependencies = [ - "getrandom 0.4.3", + "getrandom", "libc", ] @@ -1352,16 +1300,6 @@ version = "1.70.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe" -[[package]] -name = "ordered-multimap" -version = "0.7.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "49203cdcae0030493bad186b28da2fa25645fa276a51b6fec8010d281e02ef79" -dependencies = [ - "dlv-list", - "hashbrown", -] - [[package]] name = "os_display" version = "0.1.4" @@ -1475,7 +1413,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c7f5fa3a058cd35567ef9bfa5e75732bee0f9e4c55fa90477bef2dfcdbc4be80" dependencies = [ "chacha20", - "getrandom 0.4.3", + "getrandom", "rand_core", ] @@ -1522,16 +1460,6 @@ version = "0.8.11" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4" -[[package]] -name = "rust-ini" -version = "0.21.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "796e8d2b6696392a43bea58116b667fb4c29727dc5abd27d6acf338bb4f688c7" -dependencies = [ - "cfg-if", - "ordered-multimap", -] - [[package]] name = "rustc-hash" version = "2.1.3" @@ -1743,7 +1671,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" dependencies = [ "fastrand", - "getrandom 0.4.3", + "getrandom", "once_cell", "rustix", "windows-sys", @@ -1779,15 +1707,6 @@ dependencies = [ "syn 3.0.4", ] -[[package]] -name = "tiny-keccak" -version = "2.0.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c9d3793400a45f954c52e73d068316d76b6f4e36977e3fcebb13a2721e80237" -dependencies = [ - "crunchy", -] - [[package]] name = "tinystr" version = "0.8.4" @@ -1942,7 +1861,6 @@ dependencies = [ "clap", "fluent", "nix", - "rust-ini", "thiserror", "uucore", ] @@ -2160,12 +2078,6 @@ version = "0.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5c3082ca00d5a5ef149bb8b555a72ae84c9c59f7250f013ac822ac2e49b19c64" -[[package]] -name = "wasi" -version = "0.11.1+wasi-snapshot-preview1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" - [[package]] name = "wasm-bindgen" version = "0.2.127" diff --git a/src/uu/env/Cargo.toml b/src/uu/env/Cargo.toml index 159a965a4fb..1f32567c41b 100644 --- a/src/uu/env/Cargo.toml +++ b/src/uu/env/Cargo.toml @@ -17,7 +17,6 @@ doctest = false [dependencies] clap = { workspace = true } -rust-ini = { workspace = true } thiserror = { workspace = true } uucore = { workspace = true, features = ["signals"] } fluent = { workspace = true } diff --git a/src/uu/env/locales/en-US.ftl b/src/uu/env/locales/en-US.ftl index d301e847435..60f9261816e 100644 --- a/src/uu/env/locales/en-US.ftl +++ b/src/uu/env/locales/en-US.ftl @@ -6,7 +6,6 @@ env-after-help = A mere - implies -i. If no COMMAND, print the resulting environ env-help-ignore-environment = start with an empty environment env-help-chdir = change working directory to DIR env-help-null = end each output line with a 0 byte rather than a newline (only valid when printing the environment) -env-help-file = read and set variables from a ".env"-style configuration file (prior to any unset and/or set) env-help-unset = remove variable from the environment env-help-debug = print verbose information for each processing step env-help-split-string = process and split S into separate arguments; used to pass multiple arguments on shebang lines diff --git a/src/uu/env/locales/fr-FR.ftl b/src/uu/env/locales/fr-FR.ftl index c8c66cda4b5..997456baca3 100644 --- a/src/uu/env/locales/fr-FR.ftl +++ b/src/uu/env/locales/fr-FR.ftl @@ -6,7 +6,6 @@ env-after-help = Un simple - implique -i. Si aucune COMMANDE, afficher l'environ env-help-ignore-environment = commencer avec un environnement vide env-help-chdir = changer le répertoire de travail vers RÉP env-help-null = terminer chaque ligne de sortie avec un octet 0 plutôt qu'un retour à la ligne (valide uniquement lors de l'affichage de l'environnement) -env-help-file = lire et définir les variables à partir d'un fichier de configuration de style ".env" (avant toute suppression et/ou définition) env-help-unset = supprimer la variable de l'environnement env-help-debug = afficher des informations détaillées pour chaque étape de traitement env-help-split-string = traiter et diviser S en arguments séparés ; utilisé pour passer plusieurs arguments sur les lignes shebang diff --git a/src/uu/env/src/env.rs b/src/uu/env/src/env.rs index 579382f9bea..02505edbed5 100644 --- a/src/uu/env/src/env.rs +++ b/src/uu/env/src/env.rs @@ -14,7 +14,6 @@ pub mod variable_parser; use clap::builder::ValueParser; use clap::{Arg, ArgAction, Command}; -use ini::Ini; use native_int_str::{ Convert, NCvt, NativeIntStr, NativeIntString, NativeStr, from_native_int_representation, from_native_int_representation_owned, get_single_native_int_value, @@ -34,6 +33,7 @@ use std::env; #[cfg(unix)] use std::ffi::CString; use std::ffi::{OsStr, OsString}; +#[cfg(not(unix))] use std::io; use std::io::Write as _; use std::io::stderr; @@ -91,7 +91,6 @@ mod options { pub const IGNORE_ENVIRONMENT: &str = "ignore-environment"; pub const CHDIR: &str = "chdir"; pub const NULL: &str = "null"; - pub const FILE: &str = "file"; pub const UNSET: &str = "unset"; pub const DEBUG: &str = "debug"; pub const SPLIT_STRING: &str = "split-string"; @@ -106,7 +105,6 @@ struct Options<'a> { ignore_env: bool, line_ending: LineEnding, running_directory: Option<&'a OsStr>, - files: Vec<&'a OsStr>, unsets: Vec<&'a OsStr>, sets: Vec<(Cow<'a, OsStr>, Cow<'a, OsStr>)>, program: Vec<&'a OsStr>, @@ -313,34 +311,6 @@ fn signal_is_valid(sig: usize) -> bool { true } -fn load_config_file(opts: &mut Options) -> UResult<()> { - // NOTE: config files are parsed using an INI parser b/c it's available and compatible with ".env"-style files - // ... * but support for actual INI files, although working, is not intended, nor claimed - for &file in &opts.files { - let conf = if file == "-" { - let stdin = io::stdin(); - let mut stdin_locked = stdin.lock(); - Ini::read_from(&mut stdin_locked) - } else { - Ini::load_from_file(file) - }; - - let conf = - conf.map_err(|e| USimpleError::new(1, format!("{}: {e}", file.maybe_quote())))?; - - for (_, prop) in &conf { - // ignore all INI section lines (treat them as comments) - for (key, value) in prop { - unsafe { - env::set_var(key, value); - } - } - } - } - - Ok(()) -} - pub fn uu_app() -> Command { Command::new("env") .version(uucore::crate_version!()) @@ -374,16 +344,6 @@ pub fn uu_app() -> Command { .help(translate!("env-help-null")) .action(ArgAction::SetTrue), ) - .arg( - Arg::new(options::FILE) - .short('f') - .long(options::FILE) - .value_name("PATH") - .value_hint(clap::ValueHint::FilePath) - .value_parser(ValueParser::os_string()) - .action(ArgAction::Append) - .help(translate!("env-help-file")), - ) .arg( Arg::new(options::UNSET) .short('u') @@ -616,13 +576,8 @@ impl EnvAppData { let mut process_flags = true; let mut expecting_arg = false; // Leave out split-string since it's a special case below - let flags_with_args = [ - options::ARGV0, - options::CHDIR, - options::FILE, - options::UNSET, - ]; - let short_flags_with_args = ['a', 'C', 'f', 'u']; + let flags_with_args = [options::ARGV0, options::CHDIR, options::UNSET]; + let short_flags_with_args = ['a', 'C', 'u']; let mut consumed_split_payload_arg: Option = None; for (n, arg) in original_args.iter().enumerate() { if consumed_split_payload_arg == Some(n) { @@ -821,7 +776,7 @@ impl EnvAppData { self.do_input_debug_printing = Some(false); } - let mut opts = make_options( + let opts = make_options( &matches, #[cfg(all(unix, not(target_os = "fuchsia")))] &signal_apply_all, @@ -832,9 +787,6 @@ impl EnvAppData { apply_removal_of_all_env_vars(&opts); - // load .env-style config file prior to those given on the command-line - load_config_file(&mut opts)?; - apply_unset_env_vars(&opts)?; apply_specified_env_vars(&opts); @@ -1011,10 +963,6 @@ fn make_options<'a>( let running_directory = matches .get_one::("chdir") .map(OsString::as_os_str); - let files = match matches.get_many::("file") { - Some(v) => v.map(OsString::as_os_str).collect(), - None => Vec::new(), - }; let unsets = match matches.get_many::("unset") { Some(v) => v.map(OsString::as_os_str).collect(), None => Vec::new(), @@ -1036,7 +984,6 @@ fn make_options<'a>( ignore_env, line_ending, running_directory, - files, unsets, sets: vec![], program: vec![], diff --git a/tests/by-util/test_env.rs b/tests/by-util/test_env.rs index 6ab2efb9af2..7d159c55cd3 100644 --- a/tests/by-util/test_env.rs +++ b/tests/by-util/test_env.rs @@ -275,53 +275,6 @@ fn test_debug2_part_of_string_arg() { ); } -#[test] -fn test_file_option() { - let out = new_ucmd!() - .arg("-f") - .arg("vars.conf.txt") - .succeeds() - .stdout_move_str(); - - assert_eq!( - out.lines() - .filter(|&line| line == "FOO=bar" || line == "BAR=bamf this") - .count(), - 2 - ); -} - -#[test] -fn test_combined_file_set() { - let out = new_ucmd!() - .arg("-f") - .arg("vars.conf.txt") - .arg("FOO=bar.alt") - .succeeds() - .stdout_move_str(); - - assert_eq!(out.lines().filter(|&line| line == "FOO=bar.alt").count(), 1); -} - -#[test] -fn test_combined_file_set_unset() { - let out = new_ucmd!() - .arg("-u") - .arg("BAR") - .arg("-f") - .arg("vars.conf.txt") - .arg("FOO=bar.alt") - .succeeds() - .stdout_move_str(); - - assert_eq!( - out.lines() - .filter(|&line| line == "FOO=bar.alt" || line.starts_with("BAR=")) - .count(), - 1 - ); -} - #[test] fn test_unset_invalid_variables() { use uucore::display::Quotable; @@ -510,35 +463,6 @@ fn test_fail_change_directory() { assert!(out.contains("env: cannot change directory to ")); } -#[test] -fn test_chdir_happens_after_relative_file_loading() { - let scene = TestScenario::new(util_name!()); - scene.fixtures.mkdir("target"); - scene - .fixtures - .write("config.env", "CONFIG_SOURCE=from-root\n"); - scene - .fixtures - .write("target/config.env", "CONFIG_SOURCE=from-target\n"); - - let out = scene - .ucmd() - .args(&["--chdir", "target", "--file", "config.env", "-i"]) - .arg(uutests::util::get_tests_binary()) - .arg(util_name!()) - .succeeds() - .stdout_move_str(); - - assert!( - out.contains("CONFIG_SOURCE=from-root\n"), - "expected config file from invocation directory, got: {out:?}" - ); - assert!( - !out.contains("CONFIG_SOURCE=from-target\n"), - "unexpectedly loaded config from --chdir target directory: {out:?}" - ); -} - #[cfg(not(windows))] // windows has no executable "echo", its only supported as part of a batch-file #[test] fn test_split_string_into_args_one_argument_no_quotes() { diff --git a/tests/fixtures/env/vars.conf.txt b/tests/fixtures/env/vars.conf.txt deleted file mode 100644 index 9364d6d122a..00000000000 --- a/tests/fixtures/env/vars.conf.txt +++ /dev/null @@ -1,4 +0,0 @@ -# comment -FOO=bar - -BAR="bamf this"