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:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user