gojs: implements chown (#1204)
This finishes the last remaining syscalls in `GOOS=js`. After this is merged, further bugs are easier to hunt down as we know ENOSYS is not expected on writeable file systems. Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
@@ -575,8 +575,8 @@ func (jsfsChown) invoke(ctx context.Context, mod api.Module, args ...interface{}
|
||||
gid := goos.ValueToUint32(args[2])
|
||||
callback := args[3].(funcWrapper)
|
||||
|
||||
_, _, _ = path, uid, gid // TODO
|
||||
var err error = syscall.ENOSYS
|
||||
fsc := mod.(*wasm.CallContext).Sys.FS()
|
||||
err := fsc.RootFS().Chown(path, int(uid), int(gid))
|
||||
|
||||
return jsfsInvoke(ctx, mod, callback, err)
|
||||
}
|
||||
@@ -592,8 +592,14 @@ func (jsfsFchown) invoke(ctx context.Context, mod api.Module, args ...interface{
|
||||
gid := goos.ValueToUint32(args[2])
|
||||
callback := args[3].(funcWrapper)
|
||||
|
||||
_, _, _ = fd, uid, gid // TODO
|
||||
var err error = syscall.ENOSYS
|
||||
// Check to see if the file descriptor is available
|
||||
fsc := mod.(*wasm.CallContext).Sys.FS()
|
||||
var err error
|
||||
if f, ok := fsc.LookupFile(fd); !ok {
|
||||
err = syscall.EBADF
|
||||
} else {
|
||||
err = platform.ChownFile(f.File, int(uid), int(gid))
|
||||
}
|
||||
|
||||
return jsfsInvoke(ctx, mod, callback, err)
|
||||
}
|
||||
@@ -609,8 +615,8 @@ func (jsfsLchown) invoke(ctx context.Context, mod api.Module, args ...interface{
|
||||
gid := goos.ValueToUint32(args[2])
|
||||
callback := args[3].(funcWrapper)
|
||||
|
||||
_, _, _ = path, uid, gid // TODO
|
||||
var err error = syscall.ENOSYS
|
||||
fsc := mod.(*wasm.CallContext).Sys.FS()
|
||||
err := fsc.RootFS().Lchown(path, int(uid), int(gid))
|
||||
|
||||
return jsfsInvoke(ctx, mod, callback, err)
|
||||
}
|
||||
|
||||
16
internal/gojs/testdata/writefs/main.go
vendored
16
internal/gojs/testdata/writefs/main.go
vendored
@@ -83,6 +83,12 @@ func Main() {
|
||||
} else if mode := stat.Mode() & fs.ModePerm; mode != 0o400 {
|
||||
log.Panicln("expected mode = 0o400", mode)
|
||||
}
|
||||
|
||||
// Invoke Chown in a way nothing changes, to ensure it doesn't panic.
|
||||
if err = f.Chown(-1, -1); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Finally, close it.
|
||||
if err = f.Close(); err != nil {
|
||||
log.Panicln(err)
|
||||
@@ -99,6 +105,11 @@ func Main() {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Invoke Chown in a way nothing changes, to ensure it doesn't panic.
|
||||
if err = os.Chown(file1, -1, -1); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
if stat.Mode().Type() != 0 {
|
||||
log.Panicln("expected type = 0", stat.Mode().Type())
|
||||
}
|
||||
@@ -171,6 +182,11 @@ func Main() {
|
||||
log.Panicln("expected file != link stat", file1Stat, symlinkStat)
|
||||
}
|
||||
|
||||
// Invoke Lchown in a way nothing changes, to ensure it doesn't panic.
|
||||
if err = os.Lchown(symlink, -1, -1); err != nil {
|
||||
log.Panicln(err)
|
||||
}
|
||||
|
||||
// Test removing a non-empty empty directory
|
||||
if err = syscall.Rmdir(dir); err != syscall.ENOTEMPTY {
|
||||
log.Panicln("unexpected error", err)
|
||||
|
||||
Reference in New Issue
Block a user