Skip to content

Commit afc0663

Browse files
committed
add Android support based on fallback path
1 parent 06660e6 commit afc0663

2 files changed

Lines changed: 7 additions & 17 deletions

File tree

‎library/std/src/fs/tests.rs‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -614,7 +614,6 @@ fn set_get_unix_permissions() {
614614
}
615615

616616
/// Test set_permissions_nofollow on a regular file.
617-
#[cfg(not(target_os = "android"))]
618617
#[test]
619618
fn set_get_permissions_nofollows() {
620619
let tmpdir = tmpdir();
@@ -650,7 +649,7 @@ fn set_get_permissions_nofollows() {
650649
}
651650
}
652651

653-
#[cfg(not(target_os = "android"))]
652+
/// Test set_permissions_nofollow on a symlink.
654653
#[test]
655654
fn set_get_permissions_nofollows_symlink() {
656655
#[cfg(not(windows))]

‎library/std/src/sys/fs/unix.rs‎

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -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"))]
19121900
pub 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

Comments
 (0)