Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

io: add FileInfoToDirEntry(FileInfo) #42387

Closed
rsc opened this issue Nov 5, 2020 · 10 comments
Closed

io: add FileInfoToDirEntry(FileInfo) #42387

rsc opened this issue Nov 5, 2020 · 10 comments

Comments

@rsc
Copy link
Contributor

rsc commented Nov 5, 2020

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

@rsc rsc added this to the Proposal milestone Nov 5, 2020
@josharian

This comment has been minimized.

@ianlancetaylor

This comment has been minimized.

@josharian

This comment has been minimized.

@jimmyfrasche
Copy link
Member

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?

@ianlancetaylor ianlancetaylor added this to Incoming in Proposals (old) Nov 11, 2020
@rsc
Copy link
Contributor Author

rsc commented Nov 18, 2020

@jimmyfrasche It comes up any time you implement ReadDir in an FS implementation.

@rsc rsc moved this from Incoming to Active in Proposals (old) Nov 18, 2020
@jimmyfrasche
Copy link
Member

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.

@rsc
Copy link
Contributor Author

rsc commented Dec 2, 2020

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.

@rsc rsc moved this from Active to Likely Accept in Proposals (old) Dec 2, 2020
@rsc
Copy link
Contributor Author

rsc commented Dec 9, 2020

No change in consensus, so accepted.

@rsc rsc moved this from Likely Accept to Accepted in Proposals (old) Dec 9, 2020
@rsc rsc changed the title proposal: io: add FileInfoToDirEntry(FileInfo) io: add FileInfoToDirEntry(FileInfo) Dec 9, 2020
@rsc rsc modified the milestones: Proposal, Backlog Dec 9, 2020
@gopherbot
Copy link

Change https://golang.org/cl/293649 mentions this issue: io/fs: implement FileInfoToDirEntry

@icholy
Copy link

icholy commented Apr 28, 2021

The name is kind of long. I would have preferred fs.FileInfoDir(FileInfo)

@rsc rsc mentioned this issue Jun 10, 2021
83 tasks
@golang golang locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
No open projects
Development

No branches or pull requests

6 participants