Skip to content

Commit

Permalink
os: mark the share created by TestNetworkSymbolicLink as temporary
Browse files Browse the repository at this point in the history
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 <[email protected]>
Run-TryBot: Bryan Mills <[email protected]>
Reviewed-by: Ian Lance Taylor <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
  • Loading branch information
Bryan C. Mills authored and gopherbot committed Jul 25, 2023
1 parent a3a9b10 commit 6f597a8
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
6 changes: 5 additions & 1 deletion src/internal/syscall/windows/syscall_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 19 additions & 10 deletions src/os/os_windows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand All @@ -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,
Expand All @@ -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)
}
Expand Down Expand Up @@ -509,15 +518,15 @@ 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)
if err != nil {
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)
}
}

Expand Down

0 comments on commit 6f597a8

Please sign in to comment.