Skip to content

Commit 6f597a8

Browse files
Bryan C. Millsgopherbot
Bryan C. Mills
authored andcommitted
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 <[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]>
1 parent a3a9b10 commit 6f597a8

File tree

2 files changed

+24
-11
lines changed

2 files changed

+24
-11
lines changed

src/internal/syscall/windows/syscall_windows.go

+5-1
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,11 @@ const MB_ERR_INVALID_CHARS = 8
333333
//sys MultiByteToWideChar(codePage uint32, dwFlags uint32, str *byte, nstr int32, wchar *uint16, nwchar int32) (nwrite int32, err error) = kernel32.MultiByteToWideChar
334334
//sys GetCurrentThread() (pseudoHandle syscall.Handle, err error) = kernel32.GetCurrentThread
335335

336-
const STYPE_DISKTREE = 0x00
336+
// Constants from lmshare.h
337+
const (
338+
STYPE_DISKTREE = 0x00
339+
STYPE_TEMPORARY = 0x40000000
340+
)
337341

338342
type SHARE_INFO_2 struct {
339343
Netname *uint16

src/os/os_windows_test.go

+19-10
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,8 @@ func TestNetworkSymbolicLink(t *testing.T) {
435435
dir := t.TempDir()
436436
chdir(t, dir)
437437

438-
shareName := "GoSymbolicLinkTestShare" // hope no conflictions
438+
pid := os.Getpid()
439+
shareName := fmt.Sprintf("GoSymbolicLinkTestShare%d", pid)
439440
sharePath := filepath.Join(dir, shareName)
440441
testDir := "TestDir"
441442

@@ -453,11 +454,22 @@ func TestNetworkSymbolicLink(t *testing.T) {
453454
t.Fatal(err)
454455
}
455456

457+
// Per https://learn.microsoft.com/en-us/windows/win32/api/lmshare/ns-lmshare-share_info_2:
458+
//
459+
// “[The shi2_permissions field] indicates the shared resource's permissions
460+
// for servers running with share-level security. A server running user-level
461+
// security ignores this member.
462+
// …
463+
// Note that Windows does not support share-level security.”
464+
//
465+
// So it shouldn't matter what permissions we set here.
466+
const permissions = 0
467+
456468
p := windows.SHARE_INFO_2{
457469
Netname: wShareName,
458-
Type: windows.STYPE_DISKTREE,
470+
Type: windows.STYPE_DISKTREE | windows.STYPE_TEMPORARY,
459471
Remark: nil,
460-
Permissions: 0,
472+
Permissions: permissions,
461473
MaxUses: 1,
462474
CurrentUses: 0,
463475
Path: wSharePath,
@@ -466,11 +478,8 @@ func TestNetworkSymbolicLink(t *testing.T) {
466478

467479
err = windows.NetShareAdd(nil, 2, (*byte)(unsafe.Pointer(&p)), nil)
468480
if err != nil {
469-
if err == syscall.ERROR_ACCESS_DENIED {
470-
t.Skip("you don't have enough privileges to add network share")
471-
}
472-
if err == _NERR_ServerNotStarted {
473-
t.Skip(_NERR_ServerNotStarted.Error())
481+
if err == syscall.ERROR_ACCESS_DENIED || err == _NERR_ServerNotStarted {
482+
t.Skipf("skipping: NetShareAdd: %v", err)
474483
}
475484
t.Fatal(err)
476485
}
@@ -509,15 +518,15 @@ func TestNetworkSymbolicLink(t *testing.T) {
509518
t.Fatal(err)
510519
}
511520
if got != target {
512-
t.Errorf(`os.Readlink("%s"): got %v, want %v`, link, got, target)
521+
t.Errorf(`os.Readlink(%#q): got %v, want %v`, link, got, target)
513522
}
514523

515524
got, err = filepath.EvalSymlinks(link)
516525
if err != nil {
517526
t.Fatal(err)
518527
}
519528
if got != target {
520-
t.Errorf(`filepath.EvalSymlinks("%s"): got %v, want %v`, link, got, target)
529+
t.Errorf(`filepath.EvalSymlinks(%#q): got %v, want %v`, link, got, target)
521530
}
522531
}
523532

0 commit comments

Comments
 (0)