io/fs: document how hard and symbolic links in a fs.FS should work #45470
Labels
Documentation
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone
What version of Go are you using (
go version
)?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:
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:fs.Stat(fsys, "a")
would return afs.FileInfo
where callingName()
would return"a"
, but its other methods would return the details from"b"
fs.ReadFile(fsys, "a")
would return the contents from"b"
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 separateStat
andLstat
. Does that meanfs.Stat(fsys, "some/path")
should behave likeos.Stat
, returning only the details for the link target? Which file name should be returned? Likewise, how shouldfs.ReadDir
behave? Should the details in afs.DirEntry
representing a symbolic link include the details of the link or the target? What about thefs.FileInfo
returned from the directory entry'sFileInfo
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.
The text was updated successfully, but these errors were encountered: