Skip to content

proposal: os: add File.Root method to safely convert a File into a Root #70370

@Jorropo

Description

@Jorropo

Proposal Details

I have code which opens both files and directories as files to perform various actions such as fetching and comparing generations (I need to upstream to linux once I write tests) or other metadata with SyscallConn.

Trying to use #67002 to make it less conservative with some TOCTOU edge cases prove challenging since *os.Root does not provide needed SyscallConn to fetch the generation of directories and more architecturally the current codepath is to open everything as a *os.File and then use statx to decide what to do next.


package os

// AsRoot open the File as a Root if it is a directory otherwise it errors.
// The Root is returned with a new lifetime such that each need to be closed independently.
func (*File) AsRoot() (*Root, error)

// AsFile opens the Root as a File.
// The File is returned with a new lifetime such that each need to be closed independently.
func (*Root) AsFile() (*File, error)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    Status

    Incoming

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions