1
2
3
4
5
6
7 package testenv
8
9 import (
10 "fmt"
11 "os"
12 "path/filepath"
13 "runtime"
14 "sync"
15 )
16
17 var hasSymlink = sync.OnceValues(func() (ok bool, reason string) {
18 switch runtime.GOOS {
19 case "plan9":
20 return false, ""
21 case "android", "wasip1":
22
23
24
25
26
27 dir, err := os.MkdirTemp("", "")
28 if err != nil {
29 return false, ""
30 }
31 defer func() {
32 _ = os.RemoveAll(dir)
33 }()
34 fpath := filepath.Join(dir, "testfile.txt")
35 if err := os.WriteFile(fpath, nil, 0644); err != nil {
36 return false, ""
37 }
38 if err := os.Symlink(fpath, filepath.Join(dir, "testlink")); err != nil {
39 if SyscallIsNotSupported(err) {
40 return false, fmt.Sprintf("symlinks unsupported: %s", err.Error())
41 }
42 return false, ""
43 }
44 }
45
46 return true, ""
47 })
48
View as plain text