You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I propose adding ReadFile and WriteFile methods to *os.Root:
package os
// ReadFile reads the named file in the root and returns the contents.// See [ReadFile] for more details.func (r*Root) ReadFile(namestring) ([]byte, error)
// WriteFile writes data to the named file in the root, creating it if necessary.// See [WriteFile] for more details.func (r*Root) WriteFile(namestring, data []byte, permFileMode) error
These are purely convenience functions (as are os.ReadFile and os.WriteFile). I propose adding them because:
os.ReadFile and os.WriteFile are very convenient convenience functions, and it's a shame not to have an equivalent that works with os.Root.
The io/fs package not only includes a ReadFile convenience function, it includes a ReadFileFS variant of FS containing a ReadFile method. I think that points at this being something we consider core filesystem functionality.
Reacted by AndrewHarrisSPU, jaloren, Tobias Klauser, Hubert Krauze, irsl, Alexandru Ungur and Will Faught
Could we have an os level shortcut methods as well (similar to os.OpenInRoot)? By having that, one wouldn't need to bother with closing the root for one-time operations.
Activity
gabyhelp commentedon Apr 1, 2025
Related Issues
(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)
[-]proposal: add os.Root.ReadFile/os.Root.WriteFile[/-][+]proposal: os: add Root.ReadFile & Root.WriteFile[/+]irsl commentedon Apr 4, 2025
Could we have an
oslevel shortcut methods as well (similar toos.OpenInRoot)? By having that, one wouldn't need to bother with closing the root for one-time operations.Without that, the following oneliner:
Would be around 6:
neild commentedon Apr 4, 2025
I don't think we want to have top-level functions for every Root operation. That'd be a lot of new functions.
Filed #73168 with a proposal for a single top-level
InRootfunction that would allow using any Root method as a one-liner.aclements commentedon May 14, 2025
Based on the discussion above, this proposal seems like a likely accept.
— aclements for the proposal review group
The proposal is given in #73126 (comment).
gopherbot commentedon May 19, 2025
Change https://go.dev/cl/674315 mentions this issue:
os: add Root.ReadFile and Root.WriteFileos: add Root.ReadFile and Root.WriteFile
aclements commentedon May 21, 2025
No change in consensus, so accepted. 🎉
This issue now tracks the work of implementing the proposal.
— aclements for the proposal review group
The proposal is given in #73126 (comment).
[-]proposal: os: add Root.ReadFile & Root.WriteFile[/-][+]os: add Root.ReadFile & Root.WriteFile[/+]os: add Root.ReadFile and Root.WriteFile
aclements commentedon Jun 10, 2025
@neild , should this issue be closed now?
neild commentedon Jun 10, 2025
Implemented, closing.