about summary refs log tree commit diff
path: root/library/std/src/sys
diff options
context:
space:
mode:
authorRalf Jung <post@ralfj.de>2023-08-03 12:07:42 +0200
committerRalf Jung <post@ralfj.de>2023-08-24 08:08:46 +0200
commit53a29e0e60b14486fbe06d0d68f311989d693816 (patch)
treeddeb1a1444e7354e06093e570e25ff3270e666e7 /library/std/src/sys
parent3a28887623fe7c61f7f84759f5d53fbf11f6a55e (diff)
downloadrust-53a29e0e60b14486fbe06d0d68f311989d693816.tar.gz
rust-53a29e0e60b14486fbe06d0d68f311989d693816.zip
also print clearing the environment entirely
Diffstat (limited to 'library/std/src/sys')
-rw-r--r--library/std/src/sys/unix/process/process_common.rs29
1 files changed, 17 insertions, 12 deletions
diff --git a/library/std/src/sys/unix/process/process_common.rs b/library/std/src/sys/unix/process/process_common.rs
index 3a02a6c20d9..23d9f3b78ee 100644
--- a/library/std/src/sys/unix/process/process_common.rs
+++ b/library/std/src/sys/unix/process/process_common.rs
@@ -558,20 +558,25 @@ impl fmt::Debug for Command {
             if let Some(ref cwd) = self.cwd {
                 write!(f, "cd {cwd:?} && ")?;
             }
-            // Removed env vars need a separate command.
-            // We use a single `unset` command for all of them.
-            let mut any_removed = false;
-            for (key, value_opt) in self.get_envs() {
-                if value_opt.is_none() {
-                    if !any_removed {
-                        write!(f, "unset ")?;
-                        any_removed = true;
+            if self.env.does_clear() {
+                write!(f, "env -i ")?;
+                // Altered env vars will be printed next, that should exactly work as expected.
+            } else {
+                // Removed env vars need a separate command.
+                // We use a single `unset` command for all of them.
+                let mut any_removed = false;
+                for (key, value_opt) in self.get_envs() {
+                    if value_opt.is_none() {
+                        if !any_removed {
+                            write!(f, "unset ")?;
+                            any_removed = true;
+                        }
+                        write!(f, "{} ", key.to_string_lossy())?;
                     }
-                    write!(f, "{} ", key.to_string_lossy())?;
                 }
-            }
-            if any_removed {
-                write!(f, "&& ")?;
+                if any_removed {
+                    write!(f, "&& ")?;
+                }
             }
             // Altered env vars can just be added in front of the program.
             for (key, value_opt) in self.get_envs() {