]> Cypherpunks repositories - gostls13.git/commitdiff
Revert "os/user: speed up Current on Windows"
authorQuim Muntal <quimmuntal@gmail.com>
Fri, 9 Aug 2024 18:17:57 +0000 (18:17 +0000)
committerQuim Muntal <quimmuntal@gmail.com>
Sat, 10 Aug 2024 07:44:03 +0000 (07:44 +0000)
This reverts CL 597255.

Reason for revert: Broke windows/arm64

Fixes #68822.
Updates #68312.

Change-Id: I43efabad43c74045888bb62bd27522aeaba0a64c
Reviewed-on: https://go-review.googlesource.com/c/go/+/604555
Reviewed-by: Ian Lance Taylor <iant@google.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>

src/internal/syscall/windows/security_windows.go
src/os/user/lookup_windows.go
src/os/user/user_test.go

index e528744caad1bd85f33937d811b1542e6cca72d4..95694c368a54c25080922c8536ba96b0de4039ec 100644 (file)
@@ -156,22 +156,3 @@ type UserInfo4 struct {
 //
 //go:linkname GetSystemDirectory
 func GetSystemDirectory() string // Implemented in runtime package.
-
-// GetUserName retrieves the user name of the current thread
-// in the specified format.
-func GetUserName(format uint32) (string, error) {
-       n := uint32(50)
-       for {
-               b := make([]uint16, n)
-               e := syscall.GetUserNameEx(format, &b[0], &n)
-               if e == nil {
-                       return syscall.UTF16ToString(b[:n]), nil
-               }
-               if e != syscall.ERROR_MORE_DATA {
-                       return "", e
-               }
-               if n <= uint32(len(b)) {
-                       return "", e
-               }
-       }
-}
index c319324d113a137611550fd66aaeaf25ffa10838..f259269a5393ecf60fff10d886d93d292f83f531 100644 (file)
@@ -232,22 +232,12 @@ func current() (*User, error) {
                if e != nil {
                        return e
                }
-               username, e := windows.GetUserName(syscall.NameSamCompatible)
+               username, domain, e := lookupUsernameAndDomain(u.User.Sid)
                if e != nil {
                        return e
                }
-               displayName, e := windows.GetUserName(syscall.NameDisplay)
-               if e != nil {
-                       return e
-               }
-               usr = &User{
-                       Uid:      uid,
-                       Gid:      gid,
-                       Username: username,
-                       Name:     displayName,
-                       HomeDir:  dir,
-               }
-               return nil
+               usr, e = newUser(uid, gid, dir, username, domain)
+               return e
        })
        return usr, err
 }
index 31486aed03381970896c417dc84a8f529bb305ac..fa597b78ece7c836595ce6b6cbdec039613d4e4b 100644 (file)
@@ -45,9 +45,8 @@ func TestCurrent(t *testing.T) {
 }
 
 func BenchmarkCurrent(b *testing.B) {
-       // Benchmark current instead of Current because Current caches the result.
        for i := 0; i < b.N; i++ {
-               current()
+               Current()
        }
 }