From 80a6b95e731c57f8ca3466e4c600de032bc0df95 Mon Sep 17 00:00:00 2001 From: richerfu <32590310+richerfu@users.noreply.github.com> Date: Thu, 19 Nov 2026 20:50:10 +0800 Subject: [PATCH] Avoid openat2 on OpenHarmony --- cap-primitives/src/rustix/linux/fs/mod.rs | 30 ++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/cap-primitives/src/rustix/linux/fs/mod.rs b/cap-primitives/src/rustix/linux/fs/mod.rs index fd85ffce..e8c36e1a 100644 --- a/cap-primitives/src/rustix/linux/fs/mod.rs +++ b/cap-primitives/src/rustix/linux/fs/mod.rs @@ -1,35 +1,37 @@ -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] mod canonicalize_impl; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] mod file_metadata; mod file_path; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] mod open_entry_impl; +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] mod open_impl; mod procfs; mod set_permissions_impl; mod set_times_impl; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] mod stat_impl; -#[cfg(target_os = "android")] -pub(crate) use crate::fs::manually::canonicalize as canonicalize_impl; -#[cfg(target_os = "android")] -pub(crate) use crate::fs::manually::open_entry as open_entry_impl; -#[cfg(target_os = "android")] -pub(crate) use crate::fs::manually::stat as stat_impl; +// Android and OHOS app sandboxes can terminate the process on openat2. +#[cfg(any(target_os = "android", target_env = "ohos"))] +pub(crate) use crate::fs::manually::{ + canonicalize as canonicalize_impl, open as open_impl, open_entry as open_entry_impl, + stat as stat_impl, +}; pub(crate) use crate::fs::via_parent::set_times_nofollow as set_times_nofollow_impl; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] pub(crate) use canonicalize_impl::canonicalize_impl; pub(crate) use file_path::file_path; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] pub(crate) use open_entry_impl::open_entry_impl; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] pub(crate) use open_impl::open_beneath; +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] pub(crate) use open_impl::open_impl; pub(crate) use set_permissions_impl::set_permissions_impl; pub(crate) use set_times_impl::set_times_impl; -#[cfg(target_os = "linux")] +#[cfg(all(target_os = "linux", not(target_env = "ohos")))] pub(crate) use stat_impl::stat_impl; // In theory we could optimize `link` using `openat2` with `O_PATH` and