-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-wasi_ext`#[feature(wasi_ext)]``#[feature(wasi_ext)]`T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Description
The methods in std::os::wasi::fs::FileExt
look a lot like the POSIX *at
methods. Would it be possible to make this extension available for all Unix platforms, rather than limiting it to wasi?
There are a lot of reasons to want to use these methods from other Unix operating systems:
- They make it possible to work with paths longer than MAX_PATH.
- They are the only way to interact with files in a Capsicum sandbox on FreeBSD.
- They can prevent TOCTOU vulnerabilities where a directory is moved between accesses to files within that directory.
Tracking issue for wasi_ext
: #71213
joseluis and Scripter17
Metadata
Metadata
Assignees
Labels
A-ioArea: `std::io`, `std::fs`, `std::net` and `std::path`Area: `std::io`, `std::fs`, `std::net` and `std::path`C-enhancementCategory: An issue proposing an enhancement or a PR with one.Category: An issue proposing an enhancement or a PR with one.F-wasi_ext`#[feature(wasi_ext)]``#[feature(wasi_ext)]`T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.Relevant to the library API team, which will review and decide on the PR/issue.
Type
Projects
Milestone
Relationships
Development
Select code repository
Activity
wasi_ext
#71213ChrisDenton commentedon Oct 7, 2022
There is definitely a lot of interest in bringing
*at
style functions to more that justos::wasi
. The ideal would be to have cross-platform APIs where possible rather than something Unix specific.the8472 commentedon Oct 8, 2022
I don't think the wasi API is ideal. Usually you need to hold onto a directory and be able to iterate it at the same time. So the
*at
methods should primarily be available on aReadDir
and optionally onFile
.If we do this in std then this can be done via a trait or a Fd wrapper type.
But if we want to let other crates handle this, e.g. to support async support then they'd need a way to get access to the file descriptor in
ReadDir
. But that's problematic due to the posix spec:There are ways around this by making the function
unsafe
, by attempting to reopen the file descriptor (which can fail) or by usinggetdents
-style syscalls on each platform. Each of those approaches has downsides.Or perhaps we could ask the standards body to clarify why this is UB. If it were merely implementation-defined behavior we could shrug and let people get the file descriptor at the risk of getting garbage when using the descriptor for multiple concurrent directory iterations.
Anyway, some design work is needed.
Some prior discussion
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/Path.20reform.202022
https://rust-lang.zulipchat.com/#narrow/stream/219381-t-libs/topic/ReadDir's.20fd