Skip to content

Suggestion: treat WASI preopen dirs as path prefixes #82339

@RReverser

Description

@RReverser

Rust stdlib already has a concept of path prefixes (std::path::Prefix, std::path::PrefixComponent etc.), although they are applied only to Windows paths.

WASI paths are currently treated as starting with a root / (e.g. path.components() returns each level starting from Component::RootDir aka /), even though WASI recognises only paths starting with a specific prefix that matches one of the preopen directories specified at startup. The levels above those prefixes don't "exist", and most APIs under WASI don't permit crossing boundaries and resolving relative paths or symlinks from a path rooted under one preopen directory to another.

The question of exposing an API corresponding to the (currently private) open_parent arisen several times in the past, as it's important to split the preopen dir from the relative path whenever dealing with lower-level WASI syscalls.

Given the above, I feel like there is a lot of conceptual similarity between WASI preopen dirs and the std::path::Prefix, and the latter would be a natural API to use for exposing the former. We'd only need to add another variant to std::path::Prefix as well as check against the preopened dirs when splitting Path into components.

@alexcrichton @sunfishcode would love your thoughts on this idea.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.O-wasmTarget: WASM (WebAssembly), http://webassembly.org/T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions