Tracking Issue for directory handles · Issue #120426 · rust-lang/rust (original) (raw)
Feature gate: #![feature(dirfd)]
This is a tracking issue for directory handles. Such handles provide a stable reference to an underlying filesystem object (typically directories) that are less vulnerable to TOCTOU attacks and similar races. These security properties will be platform-dependent. Platforms that don't provide the necessary primitives will fall back to operations on absolute paths.
Additionally they may also provide performance benefits by avoiding repeated path lookups when performing many operations on a directory.
Sandboxing is a non-goal. If a platform supports upwards path traversal via ..
or symlinks then directory handles will not prevent that. Providing O_BENEATH
-style traversal is left to 3rd-party crates or future extensions.
Public API
impl Dir {
pub fn open<P: AsRef
/// ... more convenience methods
}
impl DirEntry { pub fn open(&self) -> Result /// This could be put on OpenOptions instead pub fn open_with(&self, options: &OpenOptions) -> Result pub fn remove_file(&self) -> Result<()> pub fn remove_dir(&self) -> Result<()> }
Steps / History
- ACP: Add openat/unlinkat/etc. abstractions to ReadDir/DirEntry/OpenOptions libs-team#259
- portable, insecure
openat
emulation based onPath
s - real impls for various platforms
getdents
to get free conversion between dirfds andReadDir
- add more
*at
calls - Final comment period (FCP)1
- Stabilization PR
Unresolved Questions
- None yet.