Function cap_primitives::fs::stat
source · pub fn stat(start: &File, path: &Path, follow: FollowSymlinks) -> Result<Metadata>
Expand description
Perform an fstatat
-like operation, ensuring that the resolution of the
path never escapes the directory tree rooted at start
.
Examples found in repository?
src/windows/fs/remove_dir_all_impl.rs (line 10)
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)
}
}