Use login shell PATH for extension hooks
Some checks failed
Weekly OSV dependency audit / dependency-audit (push) Failing after 5s
Some checks failed
Weekly OSV dependency audit / dependency-audit (push) Failing after 5s
This commit is contained in:
26
src/agent.rs
26
src/agent.rs
@@ -288,6 +288,20 @@ fn shell_environment() -> Vec<(OsString, OsString)> {
|
||||
.unwrap_or_else(|| std::env::vars_os().collect())
|
||||
}
|
||||
|
||||
fn environment_path(environment: &[(OsString, OsString)]) -> Option<OsString> {
|
||||
environment
|
||||
.iter()
|
||||
.find_map(|(name, value)| (name == OsStr::new("PATH")).then(|| value.clone()))
|
||||
}
|
||||
|
||||
pub(crate) fn shell_path() -> OsString {
|
||||
USER_SHELL_ENVIRONMENT
|
||||
.get()
|
||||
.and_then(|environment| environment_path(environment))
|
||||
.or_else(|| std::env::var_os("PATH"))
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
fn shell_process(shell: &OsStr, command: &str) -> Command {
|
||||
let mut process = Command::new("/bin/sh");
|
||||
process
|
||||
@@ -4573,9 +4587,9 @@ mod tests {
|
||||
Some(directory.as_os_str()),
|
||||
Some(directory.as_os_str()),
|
||||
)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.collect::<HashMap<_, _>>();
|
||||
.unwrap();
|
||||
let path = environment_path(&environment).unwrap();
|
||||
let environment = environment.into_iter().collect::<HashMap<_, _>>();
|
||||
assert_eq!(
|
||||
environment.get(OsStr::new("DS4_LOGIN")),
|
||||
Some(&OsString::from("loaded"))
|
||||
@@ -4584,11 +4598,7 @@ mod tests {
|
||||
environment.get(OsStr::new("DS4_INTERACTIVE")),
|
||||
Some(&OsString::from("loaded"))
|
||||
);
|
||||
let path = environment
|
||||
.get(OsStr::new("PATH"))
|
||||
.unwrap()
|
||||
.to_string_lossy();
|
||||
assert!(path.starts_with(&format!(
|
||||
assert!(path.to_string_lossy().starts_with(&format!(
|
||||
"{}/interactive-bin:{}/login-bin:",
|
||||
directory.display(),
|
||||
directory.display()
|
||||
|
||||
Reference in New Issue
Block a user