diff options
| author | bors <bors@rust-lang.org> | 2017-12-24 20:57:20 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2017-12-24 20:57:20 +0000 |
| commit | c284f8807eb3a1d728242bb6a767b0306d6f6bd5 (patch) | |
| tree | 7e9882d51643927aa2160bdcb7ecd9cad0df36d2 /src/libstd/sys/redox | |
| parent | b9e4d3417fbd89563fcf15238d6741ffdee600bf (diff) | |
| parent | ccc91d7b4873a50678b3f65c895290915c54f6f5 (diff) | |
Auto merge of #46789 - Diggsey:command-env-capture, r=dtolnay
Capture `Command` environment at spawn Fixes #28975 This tracks a set of changes to the environment and then replays them at spawn time.
Diffstat (limited to 'src/libstd/sys/redox')
| -rw-r--r-- | src/libstd/sys/redox/process.rs | 24 |
1 files changed, 7 insertions, 17 deletions
diff --git a/src/libstd/sys/redox/process.rs b/src/libstd/sys/redox/process.rs index d87364b8121..3fd54973896 100644 --- a/src/libstd/sys/redox/process.rs +++ b/src/libstd/sys/redox/process.rs @@ -8,8 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -use collections::hash_map::HashMap; -use env::{self, split_paths}; +use env::{split_paths}; use ffi::OsStr; use os::unix::ffi::OsStrExt; use fmt; @@ -19,6 +18,7 @@ use sys::fd::FileDesc; use sys::fs::{File, OpenOptions}; use sys::pipe::{self, AnonPipe}; use sys::{cvt, syscall}; +use sys_common::process::{CommandEnv, DefaultEnvKey}; //////////////////////////////////////////////////////////////////////////////// // Command @@ -44,7 +44,7 @@ pub struct Command { // other keys. program: String, args: Vec<String>, - env: HashMap<String, String>, + env: CommandEnv<DefaultEnvKey>, cwd: Option<String>, uid: Option<u32>, @@ -90,7 +90,7 @@ impl Command { Command { program: program.to_str().unwrap().to_owned(), args: Vec::new(), - env: HashMap::new(), + env: Default::default(), cwd: None, uid: None, gid: None, @@ -106,16 +106,8 @@ impl Command { self.args.push(arg.to_str().unwrap().to_owned()); } - pub fn env(&mut self, key: &OsStr, val: &OsStr) { - self.env.insert(key.to_str().unwrap().to_owned(), val.to_str().unwrap().to_owned()); - } - - pub fn env_remove(&mut self, key: &OsStr) { - self.env.remove(key.to_str().unwrap()); - } - - pub fn env_clear(&mut self) { - self.env.clear(); + pub fn env_mut(&mut self) -> &mut CommandEnv<DefaultEnvKey> { + &mut self.env } pub fn cwd(&mut self, dir: &OsStr) { @@ -309,9 +301,7 @@ impl Command { args.push([arg.as_ptr() as usize, arg.len()]); } - for (key, val) in self.env.iter() { - env::set_var(key, val); - } + self.env.apply(); let program = if self.program.contains(':') || self.program.contains('/') { Some(PathBuf::from(&self.program)) |
