1- //! This defines `unlink `, the primary entrypoint to sandboxed file removal.
1+ //! This defines `remove_file `, the primary entrypoint to sandboxed file removal.
22
3- use crate :: fs:: unlink_impl ;
3+ use crate :: fs:: remove_file_impl ;
44#[ cfg( racy_asserts) ]
5- use crate :: fs:: { manually, map_result, stat_unchecked, unlink_unchecked, FollowSymlinks , Metadata } ;
5+ use crate :: fs:: {
6+ manually, map_result, remove_file_unchecked, stat_unchecked, FollowSymlinks , Metadata ,
7+ } ;
68use std:: { fs, io, path:: Path } ;
79
8- /// Perform a `unlinkat `-like operation, ensuring that the resolution of the path
9- /// never escapes the directory tree rooted at `start`.
10+ /// Perform a `remove_fileat `-like operation, ensuring that the resolution of
11+ /// the path never escapes the directory tree rooted at `start`.
1012#[ cfg_attr( not( racy_asserts) , allow( clippy:: let_and_return) ) ]
1113#[ inline]
12- pub fn unlink ( start : & fs:: File , path : & Path ) -> io:: Result < ( ) > {
14+ pub fn remove_file ( 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 = unlink_impl ( start, path) ;
19+ let result = remove_file_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_unlink ( start, path, & stat_before, & result, & stat_after) ;
25+ check_remove_file ( 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_unlink (
32+ fn check_remove_file (
3133 start : & fs:: File ,
3234 path : & Path ,
3335 stat_before : & io:: Result < Metadata > ,
@@ -56,13 +58,13 @@ fn check_unlink(
5658 path,
5759 FollowSymlinks :: No ,
5860 ) ) {
59- Ok ( canon) => match map_result ( & unlink_unchecked ( start, & canon) ) {
61+ Ok ( canon) => match map_result ( & remove_file_unchecked ( start, & canon) ) {
6062 Err ( ( _unchecked_kind, _unchecked_message) ) => {
6163 /* TODO: Check error messages.
6264 assert_eq!(
6365 kind,
6466 unchecked_kind,
65- "unexpected error kind from unlink start='{:?}', \
67+ "unexpected error kind from remove_file start='{:?}', \
6668 path='{}':\nstat_before={:#?}\nresult={:#?}\nstat_after={:#?}",
6769 start,
6870 path.display(),
@@ -73,7 +75,7 @@ fn check_unlink(
7375 assert_eq!(message, unchecked_message);
7476 */
7577 }
76- _ => panic ! ( "unsandboxed unlink success" ) ,
78+ _ => panic ! ( "unsandboxed remove_file success" ) ,
7779 } ,
7880 Err ( ( _canon_kind, _canon_message) ) => {
7981 /* TODO: Check error messages.
@@ -85,7 +87,7 @@ fn check_unlink(
8587 }
8688
8789 other => panic ! (
88- "inconsistent unlink checks: start='{:?}' path='{}':\n {:#?}" ,
90+ "inconsistent remove_file checks: start='{:?}' path='{}':\n {:#?}" ,
8991 start,
9092 path. display( ) ,
9193 other,
@@ -94,15 +96,15 @@ fn check_unlink(
9496
9597 match ( result, stat_after) {
9698 ( Ok ( ( ) ) , Ok ( _unchecked_metadata) ) => panic ! (
97- "file still exists after unlink start='{:?}', path='{}'" ,
99+ "file still exists after remove_file start='{:?}', path='{}'" ,
98100 start,
99101 path. display( )
100102 ) ,
101103 ( Err ( e) , Ok ( unchecked_metadata) ) => match e. kind ( ) {
102104 io:: ErrorKind :: PermissionDenied => ( ) ,
103105 io:: ErrorKind :: Other if unchecked_metadata. is_dir ( ) => ( ) ,
104106 _ => panic ! (
105- "unexpected error unlinking start='{:?}', path='{}': {:?}" ,
107+ "unexpected error removing file start='{:?}', path='{}': {:?}" ,
106108 start,
107109 path. display( ) ,
108110 e
0 commit comments