From d04635478acf531f2e2fbb7de668dfc456832c11 Mon Sep 17 00:00:00 2001 From: topjohnwu Date: Fri, 31 Jul 2026 15:51:05 -0700 Subject: [PATCH] Fix clippy warnings across native codebase Address clippy warnings including collapsible match statements in bootstages, daemon, su daemon, and db modules, as well as iterator loops in files.rs. Assisted-by: Gemini 3.6 Flash --- native/src/base/files.rs | 7 ++----- native/src/core/bootstages.rs | 12 ++++++------ native/src/core/daemon.rs | 30 +++++++++++++----------------- native/src/core/su/daemon.rs | 16 ++++++---------- native/src/core/su/db.rs | 18 +++--------------- 5 files changed, 30 insertions(+), 53 deletions(-) diff --git a/native/src/base/files.rs b/native/src/base/files.rs index ca944f682..3ea32dfae 100644 --- a/native/src/base/files.rs +++ b/native/src/base/files.rs @@ -422,16 +422,13 @@ impl Utf8CStr { } let mut path = cstr::buf::default(); - let mut components = self.split('/').filter(|s| !s.is_empty()); + let components = self.split('/').filter(|s| !s.is_empty()); if self.starts_with('/') { path.append_path("/"); } - loop { - let Some(s) = components.next() else { - break; - }; + for s in components { path.append_path(s); path.mkdir(mode)?; } diff --git a/native/src/core/bootstages.rs b/native/src/core/bootstages.rs index 1ad4c4646..f704d89b7 100644 --- a/native/src/core/bootstages.rs +++ b/native/src/core/bootstages.rs @@ -195,13 +195,13 @@ impl MagiskD { let mut state = self.boot_stage_lock.lock(); match code { - RequestCode::POST_FS_DATA => { - if check_data() && !state.contains(BootState::PostFsDataDone) { - if self.post_fs_data() { - state.insert(BootState::SafeMode); - } - state.insert(BootState::PostFsDataDone); + RequestCode::POST_FS_DATA + if check_data() && !state.contains(BootState::PostFsDataDone) => + { + if self.post_fs_data() { + state.insert(BootState::SafeMode); } + state.insert(BootState::PostFsDataDone); } RequestCode::LATE_START => { drop(client); diff --git a/native/src/core/daemon.rs b/native/src/core/daemon.rs index e1cea28c8..d493fb7a3 100644 --- a/native/src/core/daemon.rs +++ b/native/src/core/daemon.rs @@ -226,25 +226,21 @@ impl MagiskD { | RequestCode::ZYGOTE_RESTART | RequestCode::SQLITE_CMD | RequestCode::DENYLIST - | RequestCode::STOP_DAEMON => { - if !is_root { - client.write_pod(&RespondCode::ROOT_REQUIRED.repr).log_ok(); - return; - } + | RequestCode::STOP_DAEMON + if !is_root => + { + client.write_pod(&RespondCode::ROOT_REQUIRED.repr).log_ok(); + return; } - RequestCode::REMOVE_MODULES => { - if !is_root && !is_shell { - // Only allow root and ADB shell to remove modules - client.write_pod(&RespondCode::ACCESS_DENIED.repr).log_ok(); - return; - } + RequestCode::REMOVE_MODULES if !is_root && !is_shell => { + // Only allow root and ADB shell to remove modules + client.write_pod(&RespondCode::ACCESS_DENIED.repr).log_ok(); + return; } - RequestCode::ZYGISK => { - if !is_zygote { - // Invalid client context - client.write_pod(&RespondCode::ACCESS_DENIED.repr).log_ok(); - return; - } + RequestCode::ZYGISK if !is_zygote => { + // Invalid client context + client.write_pod(&RespondCode::ACCESS_DENIED.repr).log_ok(); + return; } _ => {} } diff --git a/native/src/core/su/daemon.rs b/native/src/core/su/daemon.rs index 23d026fe7..0a94888f7 100644 --- a/native/src/core/su/daemon.rs +++ b/native/src/core/su/daemon.rs @@ -252,17 +252,13 @@ impl MagiskD { warn!("Root access is disabled!"); return Ok(Arc::new(SuInfo::deny(uid))); } - RootAccess::AdbOnly => { - if uid != AID_SHELL { - warn!("Root access limited to ADB only!"); - return Ok(Arc::new(SuInfo::deny(uid))); - } + RootAccess::AdbOnly if uid != AID_SHELL => { + warn!("Root access limited to ADB only!"); + return Ok(Arc::new(SuInfo::deny(uid))); } - RootAccess::AppsOnly => { - if uid == AID_SHELL { - warn!("Root access is disabled for ADB!"); - return Ok(Arc::new(SuInfo::deny(uid))); - } + RootAccess::AppsOnly if uid == AID_SHELL => { + warn!("Root access is disabled for ADB!"); + return Ok(Arc::new(SuInfo::deny(uid))); } _ => {} }; diff --git a/native/src/core/su/db.rs b/native/src/core/su/db.rs index 54288c1d1..38a3d0bb5 100644 --- a/native/src/core/su/db.rs +++ b/native/src/core/su/db.rs @@ -95,26 +95,14 @@ impl MagiskD { // Check user root access settings match cfg.root_access { RootAccess::Disabled => return false, - RootAccess::AppsOnly => { - if uid == AID_SHELL { - return false; - } - } - RootAccess::AdbOnly => { - if uid != AID_SHELL { - return false; - } - } + RootAccess::AppsOnly if uid == AID_SHELL => return false, + RootAccess::AdbOnly if uid != AID_SHELL => return false, _ => {} } // Check multiuser settings match cfg.multiuser_mode { - MultiuserMode::OwnerOnly => { - if to_user_id(uid) != 0 { - return false; - } - } + MultiuserMode::OwnerOnly if to_user_id(uid) != 0 => return false, MultiuserMode::OwnerManaged => uid = to_app_id(uid), _ => {} }