]> Cypherpunks repositories - gostls13.git/commitdiff
os: mark the share created by TestNetworkSymbolicLink as temporary
authorBryan C. Mills <bcmills@google.com>
Fri, 21 Jul 2023 18:35:01 +0000 (14:35 -0400)
committerGopher Robot <gobot@golang.org>
Tue, 25 Jul 2023 00:57:39 +0000 (00:57 +0000)
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>

src/internal/syscall/windows/syscall_windows.go
src/os/os_windows_test.go

index 53d32a14a01437665300fe61b000274980d26b65..9e3c3dc8734383a3284006d186ebac3da4d83876 100644 (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  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
index a0bfd991e33c1ea5e8554117c62e0ff1391e0146..fee539a227b1e6e5a6f5eb8e745bbe07d811b75f 100644 (file)
@@ -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)
        }
 }