diff --git a/src/os/root.go b/src/os/root.go index 953cd6b9b9..d759727ce7 100644 --- a/src/os/root.go +++ b/src/os/root.go @@ -352,8 +352,8 @@ func splitPathInRoot(s string, prefix, suffix []string) (_ []string, suffixSep s // FS returns a file system (an fs.FS) for the tree of files in the root. // -// The result implements [io/fs.StatFS], [io/fs.ReadFileFS] and -// [io/fs.ReadDirFS]. +// The result implements [io/fs.StatFS], [io/fs.ReadFileFS], +// [io/fs.ReadDirFS], and [io/fs.ReadLinkFS]. func (r *Root) FS() fs.FS { return (*rootFS)(r) } @@ -409,6 +409,14 @@ func (rfs *rootFS) ReadFile(name string) ([]byte, error) { return readFileContents(statOrZero(f), f.Read) } +func (rfs *rootFS) ReadLink(name string) (string, error) { + r := (*Root)(rfs) + if !isValidRootFSPath(name) { + return "", &PathError{Op: "readlink", Path: name, Err: ErrInvalid} + } + return r.Readlink(name) +} + func (rfs *rootFS) Stat(name string) (FileInfo, error) { r := (*Root)(rfs) if !isValidRootFSPath(name) { @@ -417,6 +425,14 @@ func (rfs *rootFS) Stat(name string) (FileInfo, error) { return r.Stat(name) } +func (rfs *rootFS) Lstat(name string) (FileInfo, error) { + r := (*Root)(rfs) + if !isValidRootFSPath(name) { + return nil, &PathError{Op: "lstat", Path: name, Err: ErrInvalid} + } + return r.Lstat(name) +} + // isValidRootFSPath reports whether name is a valid filename to pass a Root.FS method. func isValidRootFSPath(name string) bool { if !fs.ValidPath(name) {