Skip to content

Commit 482e140

Browse files
authored
Revert "env: trace the environment changes under -v"
This reverts commit 9408b4f.
1 parent 9408b4f commit 482e140

2 files changed

Lines changed: 6 additions & 59 deletions

File tree

src/uu/env/src/env.rs

Lines changed: 6 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -830,14 +830,14 @@ impl EnvAppData {
830830
// NOTE: we manually set and unset the env vars below rather than using Command::env() to more
831831
// easily handle the case where no command is given
832832

833-
apply_removal_of_all_env_vars(&opts, self.do_debug_printing);
833+
apply_removal_of_all_env_vars(&opts);
834834

835835
// load .env-style config file prior to those given on the command-line
836836
load_config_file(&mut opts)?;
837837

838-
apply_unset_env_vars(&opts, self.do_debug_printing)?;
838+
apply_unset_env_vars(&opts)?;
839839

840-
apply_specified_env_vars(&opts, self.do_debug_printing);
840+
apply_specified_env_vars(&opts);
841841

842842
#[cfg(all(unix, not(target_os = "fuchsia")))]
843843
{
@@ -990,12 +990,9 @@ impl EnvAppData {
990990
}
991991
}
992992

993-
fn apply_removal_of_all_env_vars(opts: &Options<'_>, do_debug_printing: bool) {
993+
fn apply_removal_of_all_env_vars(opts: &Options<'_>) {
994994
// remove all env vars if told to ignore presets
995995
if opts.ignore_env {
996-
if do_debug_printing {
997-
let _ = writeln!(stderr(), "cleaning environ");
998-
}
999996
for (ref name, _) in env::vars_os() {
1000997
unsafe {
1001998
env::remove_var(name);
@@ -1078,13 +1075,7 @@ fn make_options<'a>(
10781075
Ok(opts)
10791076
}
10801077

1081-
fn apply_unset_env_vars(
1082-
opts: &Options<'_>,
1083-
do_debug_printing: bool,
1084-
) -> Result<(), Box<dyn UError>> {
1085-
// -i has already emptied the environment, and GNU does not log the
1086-
// individual unsets in that case.
1087-
let do_debug_printing = do_debug_printing && !opts.ignore_env;
1078+
fn apply_unset_env_vars(opts: &Options<'_>) -> Result<(), Box<dyn UError>> {
10881079
for name in &opts.unsets {
10891080
let native_name = NativeStr::new(name);
10901081
if name.is_empty()
@@ -1096,9 +1087,6 @@ fn apply_unset_env_vars(
10961087
translate!("env-error-cannot-unset-invalid", "name" => name.quote()),
10971088
));
10981089
}
1099-
if do_debug_printing {
1100-
let _ = writeln!(stderr(), "unset: {}", name.to_string_lossy());
1101-
}
11021090
unsafe {
11031091
env::remove_var(name);
11041092
}
@@ -1129,7 +1117,7 @@ fn apply_change_directory(opts: &Options<'_>) -> Result<(), Box<dyn UError>> {
11291117
Ok(())
11301118
}
11311119

1132-
fn apply_specified_env_vars(opts: &Options<'_>, do_debug_printing: bool) {
1120+
fn apply_specified_env_vars(opts: &Options<'_>) {
11331121
// set specified env vars
11341122
for (name, val) in &opts.sets {
11351123
/*
@@ -1161,14 +1149,6 @@ fn apply_specified_env_vars(opts: &Options<'_>, do_debug_printing: bool) {
11611149
);
11621150
continue;
11631151
}
1164-
if do_debug_printing {
1165-
let _ = writeln!(
1166-
stderr(),
1167-
"setenv: {}={}",
1168-
name.to_string_lossy(),
1169-
val.to_string_lossy()
1170-
);
1171-
}
11721152
unsafe {
11731153
env::set_var(name, val);
11741154
}

tests/by-util/test_env.rs

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,6 @@ fn test_debug2_part_of_string_arg() {
265265
r"arg\[2\]: '[^\n]+(\/|\\)coreutils(.exe)?'\n",
266266
r"arg\[3\]: 'echo'\n",
267267
r"arg\[4\]: 'hello2'\n",
268-
r"setenv: FOO=BAR\n",
269268
r"executing: [^\n]+(\/|\\)coreutils(.exe)?\n",
270269
r" arg\[0\]= '[^\n]+(\/|\\)coreutils(.exe)?'\n",
271270
r" arg\[1\]= 'echo'\n",
@@ -2261,35 +2260,3 @@ env: no terminating quote in -S string at position 18 for quote '''
22612260
.stderr_is("env: no terminating quote in -S string at position 18 for quote '''\n");
22622261
}
22632262
}
2264-
2265-
/// -v traces what it does to the environment before exec, as GNU does:
2266-
/// "cleaning environ" for -i, one "unset:" line per -u and one "setenv:"
2267-
/// line per assignment.
2268-
///
2269-
/// Unix only: the trace is checked around `true`, and `-i` leaves no PATH for
2270-
/// Windows to find a command with.
2271-
#[test]
2272-
#[cfg(unix)]
2273-
fn test_debug_traces_environment_changes() {
2274-
new_ucmd!()
2275-
.args(&["-v", "-u", "A", "-u", "B", "FOO=1", "true"])
2276-
.succeeds()
2277-
.stderr_contains("unset: A\nunset: B\nsetenv: FOO=1\nexecuting: true\n");
2278-
2279-
new_ucmd!()
2280-
.args(&["-v", "-i", "FOO=1", "true"])
2281-
.succeeds()
2282-
.stderr_contains("cleaning environ\nsetenv: FOO=1\nexecuting: true\n");
2283-
2284-
// -i has already emptied the environment, so the unset is not logged.
2285-
new_ucmd!()
2286-
.args(&["-v", "-i", "-u", "PATH", "true"])
2287-
.succeeds()
2288-
.stderr_contains("cleaning environ\nexecuting: true\n");
2289-
2290-
// Without -v nothing is traced.
2291-
new_ucmd!()
2292-
.args(&["-i", "-u", "A", "FOO=1", "true"])
2293-
.succeeds()
2294-
.no_stderr();
2295-
}

0 commit comments

Comments
 (0)