Function cap_primitives::fs::open_dir
source · Expand description
Open a directory by performing an openat
-like operation,
ensuring that the resolution of the path never escapes
the directory tree rooted at start
.
Examples found in repository?
src/fs/via_parent/open_parent.rs (line 24)
15 16 17 18 19 20 21 22 23 24 25 26 27 28
pub(super) fn open_parent<'path, 'borrow>(
start: MaybeOwnedFile<'borrow>,
path: &'path Path,
) -> io::Result<(MaybeOwnedFile<'borrow>, &'path OsStr)> {
let (dirname, basename) = split_parent(path).ok_or_else(errors::no_such_file_or_directory)?;
let dir = if dirname.as_os_str().is_empty() {
start
} else {
MaybeOwnedFile::owned(open_dir(&start, dirname)?)
};
Ok((dir, basename.as_os_str()))
}