gojs: implements remaining link functions (#1198)

This implements the last remaining link functions using the same logic
as WASI. In doing so, this changes the signature for FS.ReadLink to be
more similar to the rest of the functions. Particularly, it stops
reading the result into a buffer.

After this, the only syscalls left to implement in gojs are chown.

Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
Crypt Keeper
2023-03-05 16:11:36 +08:00
committed by GitHub
parent b533540485
commit a9b3301862
15 changed files with 122 additions and 79 deletions

View File

@@ -78,23 +78,14 @@ func (d *dirFS) Rename(from, to string) error {
}
// Readlink implements FS.Readlink
func (d *dirFS) Readlink(path string, buf []byte) (n int, err error) {
func (d *dirFS) Readlink(path string) (string, error) {
// Note: do not use syscall.Readlink as that causes race on Windows.
// In any case, syscall.Readlink does almost the same logic as os.Readlink.
res, err := os.Readlink(d.join(path))
dst, err := os.Readlink(d.join(path))
if err != nil {
err = platform.UnwrapOSError(err)
return
return "", platform.UnwrapOSError(err)
}
// We need to copy here, but syscall.Readlink does copy internally, so the cost is the same.
copy(buf, res)
n = len(res)
if n > len(buf) {
n = len(buf)
}
platform.SanitizeSeparator(buf[:n])
return
return platform.ToPosixPath(dst), nil
}
// Link implements FS.Link.