Skip to content

Commit 53279a6

Browse files
internal/testenv: probe for symlink on wasip1
Certain WASI runtimes do not support generic symlinks, and instead return permission errors when they are attempted. Perform a runtime probe of symlink support in hasSymlink on wasip1 to determine whether the runtime supports generic symlinks. Also perform the same probe on android. For #59583 Change-Id: Iae5b704e670650d38ee350a5a98f99dcce8b5b28 Reviewed-on: https://go-review.googlesource.com/c/go/+/490115 Auto-Submit: Johan Brandhorst-Satzkorn <[email protected]> Reviewed-by: Achille Roussel <[email protected]> TryBot-Bypass: Johan Brandhorst-Satzkorn <[email protected]> Reviewed-by: Dmitri Shuralyov <[email protected]> Run-TryBot: Johan Brandhorst-Satzkorn <[email protected]> Reviewed-by: Bryan Mills <[email protected]>
1 parent 4e8c6af commit 53279a6

File tree

3 files changed

+30
-3
lines changed

3 files changed

+30
-3
lines changed

src/internal/testenv/testenv.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ func HasSymlink() bool {
387387
func MustHaveSymlink(t testing.TB) {
388388
ok, reason := hasSymlink()
389389
if !ok {
390-
t.Skipf("skipping test: cannot make symlinks on %s/%s%s", runtime.GOOS, runtime.GOARCH, reason)
390+
t.Skipf("skipping test: cannot make symlinks on %s/%s: %s", runtime.GOOS, runtime.GOARCH, reason)
391391
}
392392
}
393393

src/internal/testenv/testenv_notunix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ package testenv
88

99
import (
1010
"errors"
11+
"io/fs"
1112
"os"
1213
)
1314

@@ -16,5 +17,5 @@ import (
1617
var Sigquit = os.Kill
1718

1819
func syscallIsNotSupported(err error) bool {
19-
return errors.Is(err, errors.ErrUnsupported)
20+
return errors.Is(err, fs.ErrPermission) || errors.Is(err, errors.ErrUnsupported)
2021
}

src/internal/testenv/testenv_notwin.go

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,39 @@
77
package testenv
88

99
import (
10+
"fmt"
11+
"os"
12+
"path/filepath"
1013
"runtime"
1114
)
1215

1316
func hasSymlink() (ok bool, reason string) {
1417
switch runtime.GOOS {
15-
case "android", "plan9":
18+
case "plan9":
1619
return false, ""
20+
case "android", "wasip1":
21+
// For wasip1, some runtimes forbid absolute symlinks,
22+
// or symlinks that escape the current working directory.
23+
// Perform a simple test to see whether the runtime
24+
// supports symlinks or not. If we get a permission
25+
// error, the runtime does not support symlinks.
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+
}
1743
}
1844

1945
return true, ""

0 commit comments

Comments
 (0)