Skip to content

io/fs: document how hard and symbolic links in a fs.FS should work #45470

Open
@SlyMarbo

Description

@SlyMarbo

What version of Go are you using (go version)?

$ go version
go version go1.16.3 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What did you do?

Write code to present a TAR archive as a fs.FS. TAR archives support hard and symbolic links, but nothing in this issue is specific to TAR.

What did you expect to see?

Documentation on how an fs.FS should behave when hard and symbolic links exist. testing/fstest.TestFS checks some of these behaviours, but it's not clear exactly how this should work.

Hard links

Given a filesystem:

/a    (hard link to /b)
/b

It seems reasonable to assume that any fs.FS APIs called with the path "a" would return the answers for "b", but with the name "a". That is:

  • Calling fs.Stat(fsys, "a") would return a fs.FileInfo where calling Name() would return "a", but its other methods would return the details from "b"
  • Calling fs.ReadFile(fsys, "a") would return the contents from "b"
  • Calling fs.ReadDir(fsys, ".") would return two fs.DirEntrys, with the names "a" and "b" but otherwise identical details.

Is this assumption correct? Could it be documented?

Symbolic links

Symbolics are a bit more tricky, because the link nature is less hidden than with hard links. Presumably, some APIs should return the details of the link, rather than the details of the file the link points to. fs.FS doesn't separate Stat and Lstat. Does that mean fs.Stat(fsys, "some/path") should behave like os.Stat, returning only the details for the link target? Which file name should be returned? Likewise, how should fs.ReadDir behave? Should the details in a fs.DirEntry representing a symbolic link include the details of the link or the target? What about the fs.FileInfo returned from the directory entry's FileInfo method?

All of this is hard to guess. I'm not particularly concerned which approach is taken, whether symbolic links behave the same as hard links, or whether links are just ignored entirely, but it would be really useful for the behaviour to be documented somewhere, ideally in the docs for fs.FS.

I know this is a tricky and tedious question, so I really appreciate your help.

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions