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