From our limited experience with #42027, it turns out to be fairly common when using WalkDir or implementing ReadDir to want to create a DirEntry from a FileInfo.
I suggest we add
package fs
// FileInfoToDirEntry returns a DirEntry implementation
// returning information from the FileInfo info.
func FileInfoToDirEntry(info FileInfo) DirEntry
The name is a bit awkward but I haven't found a better one yet.
/cc @robpike
Making it a FileInfo method would shorten the name.
FileInfo is an interface type, so technically adding a method breaks the Go 1 compatibility guarantee.
Oh, I forgot that os.FileInfo was a type alias for fs.FileInfo. Thanks.
I can imagine this coming up but I can't imagine it coming up so often it belongs in the standard library.
This could certainly be due to a lack of imagination on my part. Why/how has it come up so far?
@jimmyfrasche It comes up any time you implement ReadDir in an FS implementation.
Is it because if you have an arbitrary File that you did not implement you can only call Stat on it?
You could add a (possibly optional) method like Stat to File that returns a DirEntry. Then only real file systems would need to worry about it and those would be handled by the standard library.
I don't see anyone objecting to this, and it really does come up every time you try to implement these new interfaces, so it seems like we should include it with the new interfaces.
This seems like a likely accept. Better names welcome.
No change in consensus, so accepted.
Most helpful comment
Making it a FileInfo method would shorten the name.