File tree Expand file tree Collapse file tree 1 file changed +6
-15
lines changed Expand file tree Collapse file tree 1 file changed +6
-15
lines changed Original file line number Diff line number Diff line change @@ -17,23 +17,11 @@ func setDir(cmd *exec.Cmd, dir string) {
17
17
}
18
18
19
19
// setEnv sets cmd.Env so that key = value.
20
- //
21
- // It first removes any existing values for key, so it is safe to call
22
- // even from within cmdbootstrap.
23
20
func setEnv (cmd * exec.Cmd , key , value string ) {
24
21
kv := key + "=" + value
25
22
if cmd .Env == nil {
26
23
cmd .Env = os .Environ ()
27
24
}
28
-
29
- prefix := kv [:len (key )+ 1 ]
30
- for i , entry := range cmd .Env {
31
- if strings .HasPrefix (entry , prefix ) {
32
- cmd .Env [i ] = kv
33
- return
34
- }
35
- }
36
-
37
25
cmd .Env = append (cmd .Env , kv )
38
26
}
39
27
@@ -44,10 +32,13 @@ func unsetEnv(cmd *exec.Cmd, key string) {
44
32
}
45
33
46
34
prefix := key + "="
47
- for i , entry := range cmd .Env {
35
+ newEnv := []string {}
36
+ for _ , entry := range cmd .Env {
48
37
if strings .HasPrefix (entry , prefix ) {
49
- cmd .Env = append (cmd .Env [:i ], cmd .Env [i + 1 :]... )
50
- return
38
+ continue
51
39
}
40
+ newEnv = append (newEnv , entry )
41
+ // key may appear multiple times, so keep going.
52
42
}
43
+ cmd .Env = newEnv
53
44
}
You can’t perform that action at this time.
0 commit comments