1- //! This defines `rmdir `, the primary entrypoint to sandboxed file removal.
1+ //! This defines `remove_dir `, the primary entrypoint to sandboxed file removal.
22
3- use crate :: fs:: rmdir_impl ;
3+ use crate :: fs:: remove_dir_impl ;
44#[ cfg( racy_asserts) ]
5- use crate :: fs:: { manually, map_result, rmdir_unchecked, stat_unchecked, FollowSymlinks , Metadata } ;
5+ use crate :: fs:: {
6+ manually, map_result, remove_dir_unchecked, stat_unchecked, FollowSymlinks , Metadata ,
7+ } ;
68use std:: { fs, io, path:: Path } ;
79
810/// Perform a `rmdirat`-like operation, ensuring that the resolution of the path
911/// never escapes the directory tree rooted at `start`.
1012#[ cfg_attr( not( racy_asserts) , allow( clippy:: let_and_return) ) ]
1113#[ inline]
12- pub fn rmdir ( start : & fs:: File , path : & Path ) -> io:: Result < ( ) > {
14+ pub fn remove_dir ( start : & fs:: File , path : & Path ) -> io:: Result < ( ) > {
1315 #[ cfg( racy_asserts) ]
1416 let stat_before = stat_unchecked ( start, path, FollowSymlinks :: No ) ;
1517
1618 // Call the underlying implementation.
17- let result = rmdir_impl ( start, path) ;
19+ let result = remove_dir_impl ( start, path) ;
1820
1921 #[ cfg( racy_asserts) ]
2022 let stat_after = stat_unchecked ( start, path, FollowSymlinks :: No ) ;
2123
2224 #[ cfg( racy_asserts) ]
23- check_rmdir ( start, path, & stat_before, & result, & stat_after) ;
25+ check_remove_dir ( start, path, & stat_before, & result, & stat_after) ;
2426
2527 result
2628}
2729
2830#[ cfg( racy_asserts) ]
2931#[ allow( clippy:: enum_glob_use) ]
30- fn check_rmdir (
32+ fn check_remove_dir (
3133 start : & fs:: File ,
3234 path : & Path ,
3335 stat_before : & io:: Result < Metadata > ,
@@ -51,7 +53,7 @@ fn check_rmdir(
5153 }
5254
5355 ( _, Err ( ( InvalidInput , _) ) , _) => {
54- // `rmdir (".")` apparently returns `EINVAL`
56+ // `remove_dir (".")` apparently returns `EINVAL`
5557 }
5658
5759 ( _, Err ( ( kind, message) ) , _) => {
@@ -60,13 +62,13 @@ fn check_rmdir(
6062 path,
6163 FollowSymlinks :: No ,
6264 ) ) {
63- Ok ( canon) => match map_result ( & rmdir_unchecked ( start, & canon) ) {
65+ Ok ( canon) => match map_result ( & remove_dir_unchecked ( start, & canon) ) {
6466 Err ( ( _unchecked_kind, _unchecked_message) ) => {
6567 /* TODO: Check error messages.
6668 assert_eq!(
6769 kind,
6870 unchecked_kind,
69- "unexpected error kind from rmdir start='{:?}', \
71+ "unexpected error kind from remove_dir start='{:?}', \
7072 path='{}':\nstat_before={:#?}\nresult={:#?}\nstat_after={:#?}",
7173 start,
7274 path.display(),
@@ -78,7 +80,7 @@ fn check_rmdir(
7880 */
7981 }
8082 _ => panic ! (
81- "unsandboxed rmdir success on start={:?} path={:?}; expected {:?}: {}" ,
83+ "unsandboxed remove_dir success on start={:?} path={:?}; expected {:?}: {}" ,
8284 start, path, kind, message
8385 ) ,
8486 } ,
@@ -92,7 +94,7 @@ fn check_rmdir(
9294 }
9395
9496 other => panic ! (
95- "inconsistent rmdir checks: start='{:?}' path='{}':\n {:#?}" ,
97+ "inconsistent remove_dir checks: start='{:?}' path='{}':\n {:#?}" ,
9698 start,
9799 path. display( ) ,
98100 other,
@@ -102,16 +104,16 @@ fn check_rmdir(
102104 match stat_after {
103105 Ok ( _unchecked_metadata) => match & result {
104106 Ok ( ( ) ) => panic ! (
105- "file still exists after rmdir start='{:?}', path='{}'" ,
107+ "file still exists after remove_dir start='{:?}', path='{}'" ,
106108 start,
107109 path. display( )
108110 ) ,
109111 Err ( e) => match e. kind ( ) {
110112 io:: ErrorKind :: PermissionDenied
111- | io:: ErrorKind :: InvalidInput // `rmdir (".")` apparently returns `EINVAL`
113+ | io:: ErrorKind :: InvalidInput // `remove_dir (".")` apparently returns `EINVAL`
112114 | io:: ErrorKind :: Other => ( ) , // directory not empty, among other things
113115 _ => panic ! (
114- "unexpected error rmdiring start='{:?}', path='{}': {:?}" ,
116+ "unexpected error remove_dir'ing start='{:?}', path='{}': {:?}" ,
115117 start,
116118 path. display( ) ,
117119 e
0 commit comments