Description
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 afs.FileInfo
where callingName()
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 twofs.DirEntry
s, 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.