From bf8d6460da54f607ca07afa66be8d0f0503ef709 Mon Sep 17 00:00:00 2001 From: Ayke van Laethem Date: Tue, 2 Jul 2024 17:20:07 +0200 Subject: [PATCH] os/user: use stdlib version of this package I tried implementing enough CGo support to get the native os/user package to work. But I hit a few bugs, probably in CGo itself. Then I realized I could just as well set the osusergo build tag to disable CGo for this specific case. This actually gets the os/user package to work correctly on Linux (I confirmed it returns my name/uid/homedir etc). On other systems, it probably just returns an error if it can't determine these kinds of things. But that's no worse than the current behavior which just doesn't do anything at all. --- GNUmakefile | 2 ++ compileopts/config.go | 1 + loader/goroot.go | 1 - src/os/user/user.go | 59 ------------------------------------------- 4 files changed, 3 insertions(+), 60 deletions(-) delete mode 100644 src/os/user/user.go diff --git a/GNUmakefile b/GNUmakefile index bc0e1e48f..aaaf130d9 100644 --- a/GNUmakefile +++ b/GNUmakefile @@ -378,6 +378,7 @@ TEST_PACKAGES_LINUX := \ io/ioutil \ mime/quotedprintable \ net \ + os/user \ strconv \ testing/fstest \ text/tabwriter \ @@ -388,6 +389,7 @@ TEST_PACKAGES_DARWIN := $(TEST_PACKAGES_LINUX) TEST_PACKAGES_WINDOWS := \ compress/flate \ crypto/hmac \ + os/user \ strconv \ text/template/parse \ $(nil) diff --git a/compileopts/config.go b/compileopts/config.go index eca037503..18d3c9e4d 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -84,6 +84,7 @@ func (c *Config) BuildTags() []string { tags = append(tags, []string{ "tinygo", // that's the compiler "purego", // to get various crypto packages to work + "osusergo", // to get os/user to work "math_big_pure_go", // to get math/big to work "gc." + c.GC(), "scheduler." + c.Scheduler(), // used inside the runtime package "serial." + c.Serial()}...) // used inside the machine package diff --git a/loader/goroot.go b/loader/goroot.go index 8661bf67e..739819bce 100644 --- a/loader/goroot.go +++ b/loader/goroot.go @@ -247,7 +247,6 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool { "net/": true, "net/http/": false, "os/": true, - "os/user/": false, "reflect/": false, "runtime/": false, "sync/": true, diff --git a/src/os/user/user.go b/src/os/user/user.go deleted file mode 100644 index ee63625f2..000000000 --- a/src/os/user/user.go +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright 2016 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -package user - -import "errors" - -// User represents a user account. -type User struct { - // Uid is the user ID. - // On POSIX systems, this is a decimal number representing the uid. - // On Windows, this is a security identifier (SID) in a string format. - // On Plan 9, this is the contents of /dev/user. - Uid string - // Gid is the primary group ID. - // On POSIX systems, this is a decimal number representing the gid. - // On Windows, this is a SID in a string format. - // On Plan 9, this is the contents of /dev/user. - Gid string - // Username is the login name. - Username string - // Name is the user's real or display name. - // It might be blank. - // On POSIX systems, this is the first (or only) entry in the GECOS field - // list. - // On Windows, this is the user's display name. - // On Plan 9, this is the contents of /dev/user. - Name string - // HomeDir is the path to the user's home directory (if they have one). - HomeDir string -} - -// Current returns the current user. -// -// The first call will cache the current user information. -// Subsequent calls will return the cached value and will not reflect -// changes to the current user. -func Current() (*User, error) { - return nil, errors.New("user: Current not implemented") -} - -// Lookup always returns an error. -func Lookup(username string) (*User, error) { - return nil, errors.New("user: Lookup not implemented") -} - -// Group represents a grouping of users. -// -// On POSIX systems Gid contains a decimal number representing the group ID. -type Group struct { - Gid string // group ID - Name string // group name -} - -// LookupGroup always returns an error. -func LookupGroup(name string) (*Group, error) { - return nil, errors.New("user: LookupGroup not implemented") -}