Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement env parsing on Windows #12928

Merged
merged 1 commit into from
Jan 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/env/env_supported.go → pkg/env/env_unix.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// +build linux darwin
// +build !windows

package env

Expand Down
8 changes: 0 additions & 8 deletions pkg/env/env_unsupported.go

This file was deleted.

25 changes: 25 additions & 0 deletions pkg/env/env_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package env

// ParseSlice parses the specified slice and transforms it into an environment
// map.
func ParseSlice(s []string) (map[string]string, error) {
env := make(map[string]string, len(s))
for _, e := range s {
if len(e) > 0 && e[0] == '=' {
// The legacy Windows CMD command interpreter uses a hack, where to emulate
// DOS semantics, it uses an illegal (by windows definition) env name for
// state storage to avoid conlficting with user defined env names. This is
// used to preserve drive letter paths. E.g., typing c: from another drive
// will remember the last CWD because CMD stores it in an env named "=C:".
// Since these are illegal, they are filtered from standard user access but
// are still available in the underlying win32 API calls. Since they have
// zero value to a container, we filter as well.
continue
}

if err := parseEnv(env, e); err != nil {
return nil, err
}
}
return env, nil
}