Replace rust inner functions to try blocks

This commit is contained in:
LoveSy
2025-02-01 22:27:36 +08:00
committed by John Wu
parent 88628fdf3c
commit 3981c9665e
12 changed files with 99 additions and 116 deletions
+2 -1
View File
@@ -1,9 +1,10 @@
#![feature(format_args_nl)]
#![feature(once_cell_try)]
#![feature(try_blocks)]
use logging::setup_klog;
use mount::{is_device_mounted, switch_root};
use rootdir::{inject_magisk_rc, collect_overlay_contexts, reset_overlay_contexts};
use rootdir::{collect_overlay_contexts, inject_magisk_rc, reset_overlay_contexts};
// Has to be pub so all symbols in that crate is included
pub use magiskpolicy;
+3 -4
View File
@@ -14,7 +14,7 @@ use base::{
};
pub fn switch_root(path: &Utf8CStr) {
fn inner(path: &Utf8CStr) -> LoggedResult<()> {
let res: LoggedResult<()> = try {
debug!("Switch root to {}", path);
let mut mounts = BTreeSet::new();
let mut rootfs = Directory::open(cstr!("/"))?;
@@ -55,9 +55,8 @@ pub fn switch_root(path: &Utf8CStr) {
debug!("Cleaning rootfs");
rootfs.remove_all()?;
Ok(())
}
inner(path).ok();
};
res.ok();
}
pub fn is_device_mounted(dev: u64, target: Pin<&mut CxxString>) -> bool {