if runtime.GOARCH == "arm" || runtime.GOARCH == "arm64" {
t.Skip("can't set SetGID bit with chmod on iOS")
}
- case "windows", "plan9", "js":
- t.Skip("chown/chmod setgid are not supported on Windows, Plan 9, or JS")
+ case "windows", "plan9":
+ t.Skip("chown/chmod setgid are not supported on Windows or Plan 9")
}
var b Builder
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build aix darwin dragonfly freebsd linux netbsd openbsd solaris
+// +build aix darwin dragonfly freebsd js,wasm linux netbsd openbsd solaris
package os_test
gid := Getgid()
t.Log("gid:", gid)
if err = Lchown(linkname, -1, gid); err != nil {
+ if err, ok := err.(*PathError); ok && err.Err == syscall.ENOSYS {
+ t.Skip("lchown is unavailable")
+ }
t.Fatalf("lchown %s -1 %d: %s", linkname, gid, err)
}
sys := dir.Sys().(*syscall.Stat_t)
// See also issues: 22939, 24331
func newFileTest(t *testing.T, blocking bool) {
+ if runtime.GOOS == "js" {
+ t.Skipf("syscall.Pipe is not available on %s.", runtime.GOOS)
+ }
+
p := make([]int, 2)
if err := syscall.Pipe(p); err != nil {
t.Fatalf("pipe: %v", err)
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
-// +build aix darwin dragonfly freebsd netbsd openbsd solaris
+// +build aix darwin dragonfly freebsd js,wasm netbsd openbsd solaris
package os
// +build !darwin
// +build !dragonfly
// +build !freebsd
+// +build !js !wasm
// +build !netbsd
// +build !openbsd
// +build !solaris
if err := checkPath(path); err != nil {
return err
}
- return ENOSYS
+ _, err := fsCall("chown", path, uint32(uid), uint32(gid))
+ return err
}
func Fchown(fd int, uid, gid int) error {
- return ENOSYS
+ _, err := fsCall("fchown", fd, uint32(uid), uint32(gid))
+ return err
}
func Lchown(path string, uid, gid int) error {
if err := checkPath(path); err != nil {
return err
}
- return ENOSYS
+ if jsFS.Get("lchown") == js.Undefined() {
+ // fs.lchown is unavailable on Linux until Node.js 10.6.0
+ // TODO(neelance): remove when we require at least this Node.js version
+ return ENOSYS
+ }
+ _, err := fsCall("lchown", path, uint32(uid), uint32(gid))
+ return err
}
func UtimesNano(path string, ts []Timespec) error {
return string(buf[:n]), nil
}
-func Getegid() int { return 1 }
-func Geteuid() int { return 1 }
-func Getgid() int { return 1 }
-func Getgroups() ([]int, error) { return []int{1}, nil }
-func Getppid() int { return 2 }
-func Getpid() int { return 3 }
-func Gettimeofday(tv *Timeval) error { return ENOSYS }
-func Getuid() int { return 1 }
+func Getuid() int {
+ return jsProcess.Call("getuid").Int()
+}
+
+func Getgid() int {
+ return jsProcess.Call("getgid").Int()
+}
+
+func Geteuid() int {
+ return jsProcess.Call("geteuid").Int()
+}
+
+func Getegid() int {
+ return jsProcess.Call("getegid").Int()
+}
+
+func Getgroups() ([]int, error) {
+ array := jsProcess.Call("getgroups")
+ groups := make([]int, array.Length())
+ for i := range groups {
+ groups[i] = array.Index(i).Int()
+ }
+ return groups, nil
+}
+
+func Getpid() int {
+ return jsProcess.Get("pid").Int()
+}
+
+func Getppid() int {
+ return jsProcess.Get("ppid").Int()
+}
+
+func Umask(mask int) (oldmask int) {
+ return jsProcess.Call("umask", mask).Int()
+}
+
+func Gettimeofday(tv *Timeval) error { return ENOSYS }
+
func Kill(pid int, signum Signal) error { return ENOSYS }
func Sendfile(outfd int, infd int, offset *int64, count int) (written int, err error) {
return 0, ENOSYS