From 6f597a8a9370e1389399520d721b594277a6766b Mon Sep 17 00:00:00 2001 From: "Bryan C. Mills" Date: Fri, 21 Jul 2023 14:35:01 -0400 Subject: [PATCH] os: mark the share created by TestNetworkSymbolicLink as temporary Also use a unique share name for each run of the test. This may help with #61467, but since I couldn't reproduce the failure in the first place I don't know. It passes locally for me. For #61467. Change-Id: Ie51e3cf381063e02e4849af5c1a1ed7441ce21c0 Reviewed-on: https://go-review.googlesource.com/c/go/+/512075 Reviewed-by: Quim Muntal Run-TryBot: Bryan Mills Reviewed-by: Ian Lance Taylor TryBot-Result: Gopher Robot Auto-Submit: Bryan Mills --- .../syscall/windows/syscall_windows.go | 6 +++- src/os/os_windows_test.go | 29 ++++++++++++------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/internal/syscall/windows/syscall_windows.go b/src/internal/syscall/windows/syscall_windows.go index 53d32a14a0..9e3c3dc873 100644 --- a/src/internal/syscall/windows/syscall_windows.go +++ b/src/internal/syscall/windows/syscall_windows.go @@ -333,7 +333,11 @@ const MB_ERR_INVALID_CHARS = 8 //sys MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar //sys GetCurrentThread() (pseudoHandle syscall.Handle, err error) = kernel32.GetCurrentThread -const STYPE_DISKTREE = 0x00 +// Constants from lmshare.h +const ( + STYPE_DISKTREE = 0x00 + STYPE_TEMPORARY = 0x40000000 +) type SHARE_INFO_2 struct { Netname *uint16 diff --git a/src/os/os_windows_test.go b/src/os/os_windows_test.go index a0bfd991e3..fee539a227 100644 --- a/src/os/os_windows_test.go +++ b/src/os/os_windows_test.go @@ -435,7 +435,8 @@ func TestNetworkSymbolicLink(t *testing.T) { dir := t.TempDir() chdir(t, dir) - shareName := "GoSymbolicLinkTestShare" // hope no conflictions + pid := os.Getpid() + shareName := fmt.Sprintf("GoSymbolicLinkTestShare%d", pid) sharePath := filepath.Join(dir, shareName) testDir := "TestDir" @@ -453,11 +454,22 @@ func TestNetworkSymbolicLink(t *testing.T) { t.Fatal(err) } + // Per https://learn.microsoft.com/en-us/windows/win32/api/lmshare/ns-lmshare-share_info_2: + // + // “[The shi2_permissions field] indicates the shared resource's permissions + // for servers running with share-level security. A server running user-level + // security ignores this member. + // … + // Note that Windows does not support share-level security.” + // + // So it shouldn't matter what permissions we set here. + const permissions = 0 + p := windows.SHARE_INFO_2{ Netname: wShareName, - Type: windows.STYPE_DISKTREE, + Type: windows.STYPE_DISKTREE | windows.STYPE_TEMPORARY, Remark: nil, - Permissions: 0, + Permissions: permissions, MaxUses: 1, CurrentUses: 0, Path: wSharePath, @@ -466,11 +478,8 @@ func TestNetworkSymbolicLink(t *testing.T) { err = windows.NetShareAdd(nil, 2, (*byte)(unsafe.Pointer(&p)), nil) if err != nil { - if err == syscall.ERROR_ACCESS_DENIED { - t.Skip("you don't have enough privileges to add network share") - } - if err == _NERR_ServerNotStarted { - t.Skip(_NERR_ServerNotStarted.Error()) + if err == syscall.ERROR_ACCESS_DENIED || err == _NERR_ServerNotStarted { + t.Skipf("skipping: NetShareAdd: %v", err) } t.Fatal(err) } @@ -509,7 +518,7 @@ func TestNetworkSymbolicLink(t *testing.T) { t.Fatal(err) } if got != target { - t.Errorf(`os.Readlink("%s"): got %v, want %v`, link, got, target) + t.Errorf(`os.Readlink(%#q): got %v, want %v`, link, got, target) } got, err = filepath.EvalSymlinks(link) @@ -517,7 +526,7 @@ func TestNetworkSymbolicLink(t *testing.T) { t.Fatal(err) } if got != target { - t.Errorf(`filepath.EvalSymlinks("%s"): got %v, want %v`, link, got, target) + t.Errorf(`filepath.EvalSymlinks(%#q): got %v, want %v`, link, got, target) } }