aboutsummaryrefslogtreecommitdiff
path: root/src/internal/testenv
diff options
context:
space:
mode:
authorJohan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>2023-04-27 21:39:57 -0700
committerJohan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>2023-05-02 05:22:00 +0000
commit53279a6af372e3708afe8eaf618d56ee98edf045 (patch)
tree98b7019e0792829d85c859ff82f39de85c44a1a5 /src/internal/testenv
parent4e8c6af239b6a941dafc1288bb5e275add530873 (diff)
downloadgo-53279a6af372e3708afe8eaf618d56ee98edf045.tar.xz
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 <johan.brandhorst@gmail.com> Reviewed-by: Achille Roussel <achille.roussel@gmail.com> TryBot-Bypass: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Dmitri Shuralyov <dmitshur@google.com> Run-TryBot: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com> Reviewed-by: Bryan Mills <bcmills@google.com>
Diffstat (limited to 'src/internal/testenv')
-rw-r--r--src/internal/testenv/testenv.go2
-rw-r--r--src/internal/testenv/testenv_notunix.go3
-rw-r--r--src/internal/testenv/testenv_notwin.go28
3 files changed, 30 insertions, 3 deletions
diff --git a/src/internal/testenv/testenv.go b/src/internal/testenv/testenv.go
index aeda1f964f..d03bb0550a 100644
--- a/src/internal/testenv/testenv.go
+++ b/src/internal/testenv/testenv.go
@@ -387,7 +387,7 @@ func HasSymlink() bool {
func MustHaveSymlink(t testing.TB) {
ok, reason := hasSymlink()
if !ok {
- t.Skipf("skipping test: cannot make symlinks on %s/%s%s", runtime.GOOS, runtime.GOARCH, reason)
+ t.Skipf("skipping test: cannot make symlinks on %s/%s: %s", runtime.GOOS, runtime.GOARCH, reason)
}
}
diff --git a/src/internal/testenv/testenv_notunix.go b/src/internal/testenv/testenv_notunix.go
index 31abe8d092..a7df5f5ddc 100644
--- a/src/internal/testenv/testenv_notunix.go
+++ b/src/internal/testenv/testenv_notunix.go
@@ -8,6 +8,7 @@ package testenv
import (
"errors"
+ "io/fs"
"os"
)
@@ -16,5 +17,5 @@ import (
var Sigquit = os.Kill
func syscallIsNotSupported(err error) bool {
- return errors.Is(err, errors.ErrUnsupported)
+ return errors.Is(err, fs.ErrPermission) || errors.Is(err, errors.ErrUnsupported)
}
diff --git a/src/internal/testenv/testenv_notwin.go b/src/internal/testenv/testenv_notwin.go
index 81171fd193..30e159a6ec 100644
--- a/src/internal/testenv/testenv_notwin.go
+++ b/src/internal/testenv/testenv_notwin.go
@@ -7,13 +7,39 @@
package testenv
import (
+ "fmt"
+ "os"
+ "path/filepath"
"runtime"
)
func hasSymlink() (ok bool, reason string) {
switch runtime.GOOS {
- case "android", "plan9":
+ case "plan9":
return false, ""
+ case "android", "wasip1":
+ // For wasip1, some runtimes forbid absolute symlinks,
+ // or symlinks that escape the current working directory.
+ // Perform a simple test to see whether the runtime
+ // supports symlinks or not. If we get a permission
+ // error, the runtime does not support symlinks.
+ dir, err := os.MkdirTemp("", "")
+ if err != nil {
+ return false, ""
+ }
+ defer func() {
+ _ = os.RemoveAll(dir)
+ }()
+ fpath := filepath.Join(dir, "testfile.txt")
+ if err := os.WriteFile(fpath, nil, 0644); err != nil {
+ return false, ""
+ }
+ if err := os.Symlink(fpath, filepath.Join(dir, "testlink")); err != nil {
+ if SyscallIsNotSupported(err) {
+ return false, fmt.Sprintf("symlinks unsupported: %s", err.Error())
+ }
+ return false, ""
+ }
}
return true, ""