@@ -1896,22 +1896,11 @@ pub fn set_perm_nofollow(_p: &CStr, _perm: FilePermissions) -> io::Result<()> {
18961896 Err ( crate :: io:: ErrorKind :: Unsupported . into ( ) )
18971897}
18981898
1899- #[ cfg( target_os = "android" ) ]
1900- pub fn set_perm_nofollow ( _p : & CStr , _perm : FilePermissions ) -> io:: Result < ( ) > {
1901- // Currently Android seems to be having inconsistent behavior with fchmodat
1902- // with `AT_SYMLINK_NOFOLLOW` or openat with `O_NOFOLLOW` + fchmod.
1903- // See this issue here mentioning inconsistent behavior on fchmodat:
1904- // https://github.com/android/ndk/issues/1258
1905- // On the arm-android CI job, using fchmodat with `AT_SYMLINK_NOFOLLOW` +
1906- // fallback behavior on a symlink sets the target file's permissions,
1907- // which is incorrect behavior.
1908- Err ( crate :: io:: ErrorKind :: Unsupported . into ( ) )
1909- }
1910-
1911- #[ cfg( not( any( target_os = "android" , target_os = "vxworks" ) ) ) ]
1899+ #[ cfg( not( target_os = "vxworks" ) ) ]
19121900pub fn set_perm_nofollow ( p : & CStr , perm : FilePermissions ) -> io:: Result < ( ) > {
1901+ /// Helper function for fallback open with `O_NOFOLLOW` + `fchmod` behavior. This will
1902+ /// successfully change the permissions of non-symlinks and fail when there's a symlink.
19131903 #[ inline]
1914- /// Helper function for fallback open with `O_NOFOLLOW` + `fchmod` behavior
19151904 fn open_and_set_permissions ( p : & CStr , perm : FilePermissions ) -> io:: Result < ( ) > {
19161905 use crate :: fs:: { OpenOptions , Permissions } ;
19171906
@@ -1926,6 +1915,7 @@ pub fn set_perm_nofollow(p: &CStr, perm: FilePermissions) -> io::Result<()> {
19261915 use crate :: os:: unix:: fs:: OpenOptionsExt ;
19271916 #[ cfg( target_os = "wasi" ) ]
19281917 use crate :: os:: wasi:: fs:: OpenOptionsExt ;
1918+
19291919 options. custom_flags ( libc:: O_NOFOLLOW ) ;
19301920 }
19311921
@@ -1940,7 +1930,8 @@ pub fn set_perm_nofollow(p: &CStr, perm: FilePermissions) -> io::Result<()> {
19401930 #[ allow( unused) ]
19411931 let mut res: Result < ( ) , core:: io:: Error > = Err ( crate :: io:: ErrorKind :: Unsupported . into ( ) ) ;
19421932
1943- // These platforms support `fchmodat`, so utilize this syscall over `open` + `fchmod`
1933+ // These platforms support `fchmodat`, so utilize this syscall over `open` + `fchmod`.
1934+ // We can *not* use this on Android due to <https://github.com/android/ndk/issues/1258>.
19441935 #[ cfg( any(
19451936 target_os = "linux" ,
19461937 target_os = "macos" ,
0 commit comments