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?
More examples
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()))
}
src/windows/fs/remove_dir_all_impl.rs (line 8)
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
pub(crate) fn remove_dir_all_impl(start: &fs::File, path: &Path) -> io::Result<()> {
// Open the directory, following symlinks, to make sure it is a directory.
let file = open_dir(start, path)?;
// Test whether the path is a symlink.
let md = stat(start, path, FollowSymlinks::No)?;
drop(file);
if md.is_symlink() {
// If so, just remove the link.
remove_dir(start, path)
} else {
// Otherwise, remove the tree.
let dir = open_dir_nofollow(start, path)?;
remove_open_dir_all_impl(dir)
}
}