Commit b8d5150f authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

os/user: make Current return better error w/o cgo & complete environment

Fixes #31949

Change-Id: Ib96a43e4c56a00c5ba04e4d213255a063058ae08
Reviewed-on: https://go-review.googlesource.com/c/go/+/176337Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent a4f5c9c4
......@@ -57,7 +57,17 @@ func current() (*User, error) {
if u.Uid != "" && u.Username != "" && u.HomeDir != "" {
return u, nil
}
return u, fmt.Errorf("user: Current not implemented on %s/%s", runtime.GOOS, runtime.GOARCH)
var missing string
if u.Username == "" {
missing = "$USER"
}
if u.HomeDir == "" {
if missing != "" {
missing += ", "
}
missing += "$HOME"
}
return u, fmt.Errorf("user: Current requires cgo or %s set in environment", missing)
}
func listGroups(*User) ([]string, error) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment