Function cap_primitives::fs::remove_file
source · Expand description
Perform a remove_fileat
-like operation, ensuring that the resolution of
the path never escapes the directory tree rooted at start
.
Examples found in repository?
src/rustix/fs/remove_dir_all_impl.rs (line 14)
8 9 10 11 12 13 14 15 16 17 18 19
pub(crate) fn remove_dir_all_impl(start: &fs::File, path: &Path) -> io::Result<()> {
// Code adapted from `remove_dir_all` in Rust's
// library/std/src/sys_common/fs.rs at revision
// 108e90ca78f052c0c1c49c42a22c85620be19712.
let filetype = stat(start, path, FollowSymlinks::No)?.file_type();
if filetype.is_symlink() {
remove_file(start, path)
} else {
remove_dir_all_recursive(read_dir_nofollow(start, path)?)?;
remove_dir(start, path)
}
}