Don't insert PATH variable on Windows (#3422)

* Don't insert PATH variable on Windows

* Simplify fix

* Just centralize the var

* Add a message about why we have to workaround the issue
This commit is contained in:
JT
2021-05-13 15:03:49 +12:00
committed by GitHub
parent 874ecd6c88
commit 9b8b1bad57
10 changed files with 42 additions and 25 deletions

View File

@ -9,6 +9,11 @@ pub struct Outcome {
pub err: String,
}
#[cfg(windows)]
pub const NATIVE_PATH_ENV_VAR: &str = "Path";
#[cfg(not(windows))]
pub const NATIVE_PATH_ENV_VAR: &str = "PATH";
impl Outcome {
pub fn new(out: String, err: String) -> Outcome {
Outcome { out, err }
@ -29,7 +34,7 @@ pub fn pipeline(commands: &str) -> String {
pub fn shell_os_paths() -> Vec<std::path::PathBuf> {
let mut original_paths = vec![];
if let Some(paths) = std::env::var_os("PATH") {
if let Some(paths) = std::env::var_os(NATIVE_PATH_ENV_VAR) {
original_paths = std::env::split_paths(&paths).collect::<Vec<_>>();
}

View File

@ -18,6 +18,7 @@ macro_rules! nu {
pub use std::error::Error;
pub use std::io::prelude::*;
pub use std::process::{Command, Stdio};
pub use $crate::NATIVE_PATH_ENV_VAR;
let commands = &*format!(
"
@ -46,7 +47,7 @@ macro_rules! nu {
};
let mut process = match Command::new($crate::fs::executable_path())
.env("PATH", paths_joined)
.env(NATIVE_PATH_ENV_VAR, paths_joined)
.arg("--skip-plugins")
.arg("--no-history")
.arg("--config-file")
@ -98,6 +99,7 @@ macro_rules! nu_with_plugins {
pub use std::error::Error;
pub use std::io::prelude::*;
pub use std::process::{Command, Stdio};
pub use crate::NATIVE_PATH_ENV_VAR;
let commands = &*format!(
"
@ -126,7 +128,7 @@ macro_rules! nu_with_plugins {
};
let mut process = match Command::new($crate::fs::executable_path())
.env("PATH", paths_joined)
.env(NATIVE_PATH_ENV_VAR, paths_joined)
.stdout(Stdio::piped())
.stdin(Stdio::piped())
.stderr(Stdio::piped())

View File

@ -99,7 +99,7 @@ impl NuProcess {
Err(_) => panic!("Couldn't join paths for PATH var."),
};
command.env("PATH", paths_joined);
command.env(crate::NATIVE_PATH_ENV_VAR, paths_joined);
for env_var in &self.environment_vars {
command.env(&env_var.name, &env_var.value);