1//go:build !tinygo
2
3package sysfs
4
5import (
6 "io/fs"
7 "os"
8 "path"
9
10 experimentalsys "github.com/tetratelabs/wazero/experimental/sys"
11)
12
13// Link implements the same method as documented on sys.FS
14func (d *dirFS) Link(oldName, newName string) experimentalsys.Errno {
15 err := os.Link(d.join(oldName), d.join(newName))
16 return experimentalsys.UnwrapOSError(err)
17}
18
19// Unlink implements the same method as documented on sys.FS
20func (d *dirFS) Unlink(path string) (err experimentalsys.Errno) {
21 return unlink(d.join(path))
22}
23
24// Rename implements the same method as documented on sys.FS
25func (d *dirFS) Rename(from, to string) experimentalsys.Errno {
26 from, to = d.join(from), d.join(to)
27 return rename(from, to)
28}
29
30// Chmod implements the same method as documented on sys.FS
31func (d *dirFS) Chmod(path string, perm fs.FileMode) experimentalsys.Errno {
32 err := os.Chmod(d.join(path), perm)
33 return experimentalsys.UnwrapOSError(err)
34}
35
36// Symlink implements the same method as documented on sys.FS
37func (d *dirFS) Symlink(oldName, link string) experimentalsys.Errno {
38 // Creating a symlink with an absolute path string fails with a "not permitted" error.
39 // https://github.com/WebAssembly/wasi-filesystem/blob/v0.2.0/path-resolution.md#symlinks
40 if path.IsAbs(oldName) {
41 return experimentalsys.EPERM
42 }
43 // Note: do not resolve `oldName` relative to this dirFS. The link result is always resolved
44 // when dereference the `link` on its usage (e.g. readlink, read, etc).
45 // https://github.com/bytecodealliance/cap-std/blob/v1.0.4/cap-std/src/fs/dir.rs#L404-L409
46 err := os.Symlink(oldName, d.join(link))
47 return experimentalsys.UnwrapOSError(err)
48}