prependPath returns a copy of env with the given directory prepended to PATH.
(env []string, dir string)
| 1227 | |
| 1228 | // prependPath returns a copy of env with the given directory prepended to PATH. |
| 1229 | func prependPath(env []string, dir string) []string { |
| 1230 | const prefix = "PATH=" |
| 1231 | result := make([]string, len(env)) |
| 1232 | copy(result, env) |
| 1233 | for i, e := range result { |
| 1234 | if strings.HasPrefix(e, prefix) { |
| 1235 | result[i] = prefix + dir + string(os.PathListSeparator) + e[len(prefix):] |
| 1236 | return result |
| 1237 | } |
| 1238 | } |
| 1239 | // PATH not found in env — add it |
| 1240 | result = append(result, prefix+dir) |
| 1241 | return result |
| 1242 | } |
| 1243 | |
| 1244 | // prependPythonPath returns a copy of env with the given directory prepended to PYTHONPATH. |
| 1245 | func prependPythonPath(env []string, dir string) []string { |