@@ -2010,56 +2010,10 @@ mod remove_dir_impl {
2010
2010
use crate :: sys:: common:: small_c_string:: run_path_with_cstr;
2011
2011
use crate :: sys:: { cvt, cvt_r} ;
2012
2012
2013
- #[ cfg( not( any(
2014
- all( target_os = "linux" , target_env = "gnu" ) ,
2015
- all( target_os = "macos" , not( target_arch = "aarch64" ) )
2016
- ) ) ) ]
2013
+ #[ cfg( not( all( target_os = "linux" , target_env = "gnu" ) ) ) ]
2017
2014
use libc:: { fdopendir, openat, unlinkat} ;
2018
2015
#[ cfg( all( target_os = "linux" , target_env = "gnu" ) ) ]
2019
2016
use libc:: { fdopendir, openat64 as openat, unlinkat} ;
2020
- #[ cfg( all( target_os = "macos" , not( target_arch = "aarch64" ) ) ) ]
2021
- use macos_weak:: { fdopendir, openat, unlinkat} ;
2022
-
2023
- #[ cfg( all( target_os = "macos" , not( target_arch = "aarch64" ) ) ) ]
2024
- mod macos_weak {
2025
- use crate :: sys:: weak:: weak;
2026
- use libc:: { c_char, c_int, DIR } ;
2027
-
2028
- fn get_openat_fn ( ) -> Option < unsafe extern "C" fn ( c_int , * const c_char , c_int ) -> c_int > {
2029
- weak ! ( fn openat( c_int, * const c_char, c_int) -> c_int) ;
2030
- openat. get ( )
2031
- }
2032
-
2033
- pub fn has_openat ( ) -> bool {
2034
- get_openat_fn ( ) . is_some ( )
2035
- }
2036
-
2037
- pub unsafe fn openat ( dirfd : c_int , pathname : * const c_char , flags : c_int ) -> c_int {
2038
- get_openat_fn ( ) . map ( |openat| openat ( dirfd, pathname, flags) ) . unwrap_or_else ( || {
2039
- crate :: sys:: pal:: unix:: os:: set_errno ( libc:: ENOSYS ) ;
2040
- -1
2041
- } )
2042
- }
2043
-
2044
- pub unsafe fn fdopendir ( fd : c_int ) -> * mut DIR {
2045
- #[ cfg( all( target_os = "macos" , target_arch = "x86" ) ) ]
2046
- weak ! ( fn fdopendir( c_int) -> * mut DIR , "fdopendir$INODE64$UNIX2003" ) ;
2047
- #[ cfg( all( target_os = "macos" , target_arch = "x86_64" ) ) ]
2048
- weak ! ( fn fdopendir( c_int) -> * mut DIR , "fdopendir$INODE64" ) ;
2049
- fdopendir. get ( ) . map ( |fdopendir| fdopendir ( fd) ) . unwrap_or_else ( || {
2050
- crate :: sys:: pal:: unix:: os:: set_errno ( libc:: ENOSYS ) ;
2051
- crate :: ptr:: null_mut ( )
2052
- } )
2053
- }
2054
-
2055
- pub unsafe fn unlinkat ( dirfd : c_int , pathname : * const c_char , flags : c_int ) -> c_int {
2056
- weak ! ( fn unlinkat( c_int, * const c_char, c_int) -> c_int) ;
2057
- unlinkat. get ( ) . map ( |unlinkat| unlinkat ( dirfd, pathname, flags) ) . unwrap_or_else ( || {
2058
- crate :: sys:: pal:: unix:: os:: set_errno ( libc:: ENOSYS ) ;
2059
- -1
2060
- } )
2061
- }
2062
- }
2063
2017
2064
2018
pub fn openat_nofollow_dironly ( parent_fd : Option < RawFd > , p : & CStr ) -> io:: Result < OwnedFd > {
2065
2019
let fd = cvt_r ( || unsafe {
@@ -2172,19 +2126,7 @@ mod remove_dir_impl {
2172
2126
}
2173
2127
}
2174
2128
2175
- #[ cfg( not( all( target_os = "macos" , not( target_arch = "aarch64" ) ) ) ) ]
2176
2129
pub fn remove_dir_all ( p : & Path ) -> io:: Result < ( ) > {
2177
2130
remove_dir_all_modern ( p)
2178
2131
}
2179
-
2180
- #[ cfg( all( target_os = "macos" , not( target_arch = "aarch64" ) ) ) ]
2181
- pub fn remove_dir_all ( p : & Path ) -> io:: Result < ( ) > {
2182
- if macos_weak:: has_openat ( ) {
2183
- // openat() is available with macOS 10.10+, just like unlinkat() and fdopendir()
2184
- remove_dir_all_modern ( p)
2185
- } else {
2186
- // fall back to classic implementation
2187
- crate :: sys_common:: fs:: remove_dir_all ( p)
2188
- }
2189
- }
2190
2132
}
0 commit comments