1
0
mirror of https://github.com/golang/go synced 2024-11-26 18:16:48 -07:00

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 <quimmuntal@gmail.com>
Run-TryBot: Bryan Mills <bcmills@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Auto-Submit: Bryan Mills <bcmills@google.com>
This commit is contained in:
Bryan C. Mills 2023-07-21 14:35:01 -04:00 committed by Gopher Robot
parent a3a9b1049e
commit 6f597a8a93
2 changed files with 24 additions and 11 deletions

View File

@ -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 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 //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 { type SHARE_INFO_2 struct {
Netname *uint16 Netname *uint16

View File

@ -435,7 +435,8 @@ func TestNetworkSymbolicLink(t *testing.T) {
dir := t.TempDir() dir := t.TempDir()
chdir(t, dir) chdir(t, dir)
shareName := "GoSymbolicLinkTestShare" // hope no conflictions pid := os.Getpid()
shareName := fmt.Sprintf("GoSymbolicLinkTestShare%d", pid)
sharePath := filepath.Join(dir, shareName) sharePath := filepath.Join(dir, shareName)
testDir := "TestDir" testDir := "TestDir"
@ -453,11 +454,22 @@ func TestNetworkSymbolicLink(t *testing.T) {
t.Fatal(err) 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{ p := windows.SHARE_INFO_2{
Netname: wShareName, Netname: wShareName,
Type: windows.STYPE_DISKTREE, Type: windows.STYPE_DISKTREE | windows.STYPE_TEMPORARY,
Remark: nil, Remark: nil,
Permissions: 0, Permissions: permissions,
MaxUses: 1, MaxUses: 1,
CurrentUses: 0, CurrentUses: 0,
Path: wSharePath, Path: wSharePath,
@ -466,11 +478,8 @@ func TestNetworkSymbolicLink(t *testing.T) {
err = windows.NetShareAdd(nil, 2, (*byte)(unsafe.Pointer(&p)), nil) err = windows.NetShareAdd(nil, 2, (*byte)(unsafe.Pointer(&p)), nil)
if err != nil { if err != nil {
if err == syscall.ERROR_ACCESS_DENIED { if err == syscall.ERROR_ACCESS_DENIED || err == _NERR_ServerNotStarted {
t.Skip("you don't have enough privileges to add network share") t.Skipf("skipping: NetShareAdd: %v", err)
}
if err == _NERR_ServerNotStarted {
t.Skip(_NERR_ServerNotStarted.Error())
} }
t.Fatal(err) t.Fatal(err)
} }
@ -509,7 +518,7 @@ func TestNetworkSymbolicLink(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if got != target { 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) got, err = filepath.EvalSymlinks(link)
@ -517,7 +526,7 @@ func TestNetworkSymbolicLink(t *testing.T) {
t.Fatal(err) t.Fatal(err)
} }
if got != target { 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)
} }
} }