Skip to content

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

@dolmen

Description

@dolmen

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    LibraryProposalIssues describing a requested change to the Go standard library or x/ libraries, but not to a toolProposal

    Type

    No type

    Projects

    Status

    Declined

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions