Description
What version of Go are you using (go version
)?
$ go version go version go1.17.3 linux/amd64
Does this issue reproduce with the latest release?
Yes
What did you do?
Walked a directory with fs.WalkDir
and encountered a symlink that I wanted to read.
What did you expect to see?
A function fs.ReadLink
that behaves like os.Readlink
, but operates on an fs.FS
. Design sketch:
package fs
// ReadLink returns the destination of the named symbolic link.
//
// If fsys does not implement ReadLinkFS, then ReadLink returns an error.
func ReadLink(fsys FS, name string) (string, error)
// ReadLinkFS is the interface implemented by a file system that supports symbolic links.
type ReadLinkFS interface {
FS
// ReadLink returns the destination of the named symbolic link.
ReadLink(name string) (string, error)
}
I would also want the file system returned by os.DirFS
to have an implementation that calls os.Readlink
. IIUC archive/zip.Reader
would probably also benefit from an implementation.
An open question in my mind is whether the returned destination should be a slash-separated path or kept as-is. I think for consistency it probably should convert to a slash-separated path, but I'm not sure if this has problems on Windows.
What did you see instead?
No such API exists.
Other details
I have bandwidth to contribute an implementation of this, but I understand we're in the freeze and the earliest this could go in is Go 1.19.
This is somewhat related to #45470, but I'm not proposing changing any existing semantics, just adding a new method.
Metadata
Metadata
Assignees
Labels
Type
Projects
Status
Status