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

proposal: os: extend Root FS with interface io/fs.SubFS #72054

Open
dolmen opened this issue Mar 1, 2025 · 3 comments
Open

proposal: os: extend Root FS with interface io/fs.SubFS #72054

dolmen opened this issue Mar 1, 2025 · 3 comments
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Milestone

Comments

@dolmen
Copy link
Contributor

dolmen commented Mar 1, 2025

Proposal Details

Extend type os.Root by implementing interface io/fs.SubFS.

The implementation is almost trivial as os.Root already has an OpenRoot method:

func (rfs *rootFS) Sub(dir string) (fs.FS, error) {
    if !isValidRootFSPath(dir) {
        return nil, &PathError{Op: "sub", Path: dir, Err: ErrInvalid}
    }
    r, err := (*Root)(rfs).OpenRoot(dir)
    if err != nil {
        return nil, err
    }
    return r.FS(), nil
}

var _ fs.SubFS = (*rootFS)(nil)

The documentation of os.Root.FS() will be extend to link to fs.SubFS.

@dolmen dolmen added the Proposal label Mar 1, 2025
@gopherbot gopherbot added this to the Proposal milestone Mar 1, 2025
@gabyhelp
Copy link

gabyhelp commented Mar 1, 2025

Related Issues

(Emoji vote if this was helpful or unhelpful; more detailed feedback welcome in this discussion.)

@gabyhelp gabyhelp added the LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool label Mar 1, 2025
@ianlancetaylor
Copy link
Member

CC @neild

@ianlancetaylor ianlancetaylor moved this to Incoming in Proposals Mar 3, 2025
@neild
Copy link
Contributor

neild commented Mar 3, 2025

This seems like an obvious and useful addition to os.Root. I support this proposal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
LibraryProposal Issues describing a requested change to the Go standard library or x/ libraries, but not to a tool Proposal
Projects
Status: Incoming
Development

No branches or pull requests

5 participants