ksud: Fix macOS compile

This commit is contained in:
tiann
2023-02-03 14:46:48 +08:00
parent 8ee00839dc
commit 71cc166f72
6 changed files with 30 additions and 30 deletions

View File

@@ -2,9 +2,9 @@ use anyhow::Result;
use jwalk::{Parallelism::Serial, WalkDir};
use std::path::Path;
#[cfg(unix)]
#[cfg(target_os = "linux")]
use anyhow::{Context, Ok};
#[cfg(unix)]
#[cfg(target_os = "linux")]
use extattr::{setxattr, Flags as XattrFlags};
const SYSTEM_CON: &str = "u:object_r:system_file:s0";
@@ -12,18 +12,18 @@ const _ADB_CON: &str = "u:object_r:adb_data_file:s0";
const SELINUX_XATTR : &str = "security.selinux";
pub fn setcon<P: AsRef<Path>>(path: P, con: &str) -> Result<()> {
#[cfg(unix)]
#[cfg(target_os = "linux")]
setxattr(&path, SELINUX_XATTR, con, XattrFlags::empty())
.with_context(|| format!("Failed to change SELinux context for {}", path.as_ref().display()))?;
Ok(())
}
#[cfg(unix)]
#[cfg(target_os = "linux")]
pub fn setsyscon<P: AsRef<Path>>(path: P) -> Result<()> {
setcon(path, SYSTEM_CON)
}
#[cfg(not(unix))]
#[cfg(not(target_os = "linux"))]
pub fn setsyscon<P: AsRef<Path>>(path: P) -> Result<()> {
unimplemented!()
}
@@ -31,7 +31,7 @@ pub fn setsyscon<P: AsRef<Path>>(path: P) -> Result<()> {
pub fn restore_syscon<P: AsRef<Path>>(dir: P) -> Result<()> {
for dir_entry in WalkDir::new(dir).parallelism(Serial) {
if let Some(path) = dir_entry.ok().map(|dir_entry| dir_entry.path()) {
#[cfg(unix)]
#[cfg(target_os = "linux")]
setxattr(&path, SELINUX_XATTR, SYSTEM_CON, XattrFlags::empty()).with_context(
|| format!("Failed to change SELinux context for {}", path.display()),
)?;