Skip to content

Commit

Permalink
fix: use global env variables when executing
Browse files Browse the repository at this point in the history
  • Loading branch information
TorchedSammy committed Dec 28, 2024
1 parent c969f5e commit a02cd1d
Showing 1 changed file with 1 addition and 19 deletions.
20 changes: 1 addition & 19 deletions exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,26 +434,8 @@ func execHandle(bg bool) interp.ExecHandlerFunc {
// sh/interp but with our job handling

env := hc.Env
envList := make([]string, 0, 64)
envList := os.Environ()
env.Each(func(name string, vr expand.Variable) bool {
if name == "PATH" {
pathEnv := os.Getenv("PATH")
envList = append(envList, "PATH="+pathEnv)
return true
}

if !vr.IsSet() {
// If a variable is set globally but unset in the
// runner, we need to ensure it's not part of the final
// list. Seems like zeroing the element is enough.
// This is a linear search, but this scenario should be
// rare, and the number of variables shouldn't be large.
for i, kv := range envList {
if strings.HasPrefix(kv, name+"=") {
envList[i] = ""
}
}
}
if vr.Exported && vr.Kind == expand.String {
envList = append(envList, name+"="+vr.String())
}
Expand Down

0 comments on commit a02cd1d

Please sign in to comment.