ksud: fix clippy errors

This commit is contained in:
Rifat Azad
2025-07-14 20:52:29 +06:00
parent df07860e44
commit 8fc85993f1
18 changed files with 68 additions and 71 deletions

View File

@@ -348,7 +348,7 @@ pub fn restore(
do_cpio_cmd(
&magiskboot,
workdir,
&format!("extract {0} {0}", BACKUP_FILENAME),
&format!("extract {BACKUP_FILENAME} {BACKUP_FILENAME}"),
)?;
let sha = std::fs::read(workdir.join(BACKUP_FILENAME))?;
let sha = String::from_utf8(sha)?;
@@ -515,7 +515,7 @@ fn do_patch(
match get_current_kmi() {
Ok(value) => value,
Err(e) => {
println!("- {}", e);
println!("- {e}");
if let Some(image_path) = &image {
println!(
"- Trying to auto detect KMI version for {}",
@@ -713,7 +713,7 @@ fn calculate_sha1(file_path: impl AsRef<Path>) -> Result<String> {
}
let result = hasher.finalize();
Ok(format!("{:x}", result))
Ok(format!("{result:x}"))
}
#[cfg(target_os = "android")]
@@ -729,7 +729,7 @@ fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
do_cpio_cmd(
magiskboot,
workdir,
&format!("add 0755 {0} {0}", BACKUP_FILENAME),
&format!("add 0755 {BACKUP_FILENAME} {BACKUP_FILENAME}"),
)?;
println!("- Stock image has been backup to");
println!("- {target}");
@@ -739,7 +739,7 @@ fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
#[cfg(target_os = "android")]
fn clean_backup(sha1: &str) -> Result<()> {
println!("- Clean up backup");
let backup_name = format!("{}{}", KSU_BACKUP_FILE_PREFIX, sha1);
let backup_name = format!("{KSU_BACKUP_FILE_PREFIX}{sha1}");
let dir = std::fs::read_dir(defs::KSU_BACKUP_DIR)?;
for entry in dir.flatten() {
let path = entry.path();

View File

@@ -370,13 +370,13 @@ pub fn run() -> Result<()> {
Commands::BootInfo { command } => match command {
BootInfo::CurrentKmi => {
let kmi = crate::boot_patch::get_current_kmi()?;
println!("{}", kmi);
println!("{kmi}");
// return here to avoid printing the error message
return Ok(());
}
BootInfo::SupportedKmi => {
let kmi = crate::assets::list_supported_kmi()?;
kmi.iter().for_each(|kmi| println!("{}", kmi));
kmi.iter().for_each(|kmi| println!("{kmi}"));
return Ok(());
}
},
@@ -388,7 +388,7 @@ pub fn run() -> Result<()> {
};
if let Err(e) = &result {
log::error!("Error: {:?}", e);
log::error!("Error: {e:?}");
}
result
}

View File

@@ -30,7 +30,7 @@ fn set_kernel_param(uid: u32) -> Result<()> {
fn get_pkg_uid(pkg: &str) -> Result<u32> {
// stat /data/data/<pkg>
let uid = rustix::fs::stat(format!("/data/data/{pkg}"))
.with_context(|| format!("stat /data/data/{}", pkg))?
.with_context(|| format!("stat /data/data/{pkg}"))?
.st_uid;
Ok(uid)
}

View File

@@ -28,7 +28,7 @@ pub fn on_post_data_fs() -> Result<()> {
} else {
// Then exec common post-fs-data scripts
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
warn!("exec common post-fs-data scripts failed: {}", e);
warn!("exec common post-fs-data scripts failed: {e}");
}
}
@@ -41,21 +41,21 @@ pub fn on_post_data_fs() -> Result<()> {
if safe_mode {
warn!("safe mode, skip post-fs-data scripts and disable all modules!");
if let Err(e) = crate::module::disable_all_modules() {
warn!("disable all modules failed: {}", e);
warn!("disable all modules failed: {e}");
}
return Ok(());
}
if let Err(e) = prune_modules() {
warn!("prune modules failed: {}", e);
warn!("prune modules failed: {e}");
}
if let Err(e) = handle_updated_modules() {
warn!("handle updated modules failed: {}", e);
warn!("handle updated modules failed: {e}");
}
if let Err(e) = restorecon::restorecon() {
warn!("restorecon failed: {}", e);
warn!("restorecon failed: {e}");
}
// load sepolicy.rule
@@ -64,13 +64,13 @@ pub fn on_post_data_fs() -> Result<()> {
}
if let Err(e) = crate::profile::apply_sepolies() {
warn!("apply root profile sepolicy failed: {}", e);
warn!("apply root profile sepolicy failed: {e}");
}
// mount temp dir
if !Path::new(NO_TMPFS_PATH).exists() {
if let Err(e) = mount(KSU_MOUNT_SOURCE, TEMP_DIR, "tmpfs", MountFlags::empty(), "") {
warn!("do temp dir mount failed: {}", e);
warn!("do temp dir mount failed: {e}");
}
} else {
info!("no tmpfs requested");
@@ -79,18 +79,18 @@ pub fn on_post_data_fs() -> Result<()> {
// exec modules post-fs-data scripts
// TODO: Add timeout
if let Err(e) = crate::module::exec_stage_script("post-fs-data", true) {
warn!("exec post-fs-data scripts failed: {}", e);
warn!("exec post-fs-data scripts failed: {e}");
}
// load system.prop
if let Err(e) = crate::module::load_system_prop() {
warn!("load system.prop failed: {}", e);
warn!("load system.prop failed: {e}");
}
// mount module systemlessly by magic mount
if !Path::new(NO_MOUNT_PATH).exists() {
if let Err(e) = mount_modules_systemlessly() {
warn!("do systemless mount failed: {}", e);
warn!("do systemless mount failed: {e}");
}
} else {
info!("no mount requested");
@@ -180,7 +180,7 @@ fn catch_bootlog(logname: &str, command: Vec<&str>) -> Result<()> {
};
if let Err(e) = result {
warn!("Failed to start logcat: {:#}", e);
warn!("Failed to start logcat: {e:#}");
}
Ok(())

View File

@@ -416,14 +416,14 @@ fn do_magic_mount<P: AsRef<Path>, WP: AsRef<Path>>(
pub fn magic_mount() -> Result<()> {
if let Some(root) = collect_module_files()? {
log::debug!("collected: {:#?}", root);
log::debug!("collected: {root:#?}");
let tmp_dir = PathBuf::from(MAGIC_MOUNT_WORK_DIR);
ensure_dir_exists(&tmp_dir)?;
mount(KSU_MOUNT_SOURCE, &tmp_dir, "tmpfs", MountFlags::empty(), "").context("mount tmp")?;
mount_change(&tmp_dir, MountPropagationFlags::PRIVATE).context("make tmp private")?;
let result = do_magic_mount("/", &tmp_dir, root, false);
if let Err(e) = unmount(&tmp_dir, UnmountFlags::DETACH) {
log::error!("failed to unmount tmp {}", e);
log::error!("failed to unmount tmp {e}");
}
fs::remove_dir(tmp_dir).ok();
result

View File

@@ -258,7 +258,7 @@ pub fn prune_modules() -> Result<()> {
let uninstaller = module.join("uninstall.sh");
if uninstaller.exists() {
if let Err(e) = exec_script(uninstaller, true) {
warn!("Failed to exec uninstaller: {}", e);
warn!("Failed to exec uninstaller: {e}");
}
}
@@ -323,7 +323,7 @@ pub fn install_module(zip: &str) -> Result<()> {
module_prop.insert(k, v);
},
)?;
info!("module prop: {:?}", module_prop);
info!("module prop: {module_prop:?}");
let Some(module_id) = module_prop.get("id") else {
bail!("module id not found in module.prop!");
@@ -401,7 +401,7 @@ pub fn restore_module(id: &str) -> Result<()> {
}
pub fn run_action(id: &str) -> Result<()> {
let action_script_path = format!("/data/adb/modules/{}/action.sh", id);
let action_script_path = format!("/data/adb/modules/{id}/action.sh");
exec_script(&action_script_path, true)
}

View File

@@ -70,9 +70,9 @@ pub fn apply_sepolies() -> Result<()> {
};
let sepolicy = sepolicy.path();
if sepolicy::apply_file(&sepolicy).is_ok() {
log::info!("profile sepolicy applied: {:?}", sepolicy);
log::info!("profile sepolicy applied: {sepolicy:?}");
} else {
log::info!("profile sepolicy apply failed: {:?}", sepolicy);
log::info!("profile sepolicy apply failed: {sepolicy:?}");
}
}
Ok(())

View File

@@ -697,7 +697,7 @@ fn apply_one_rule<'a>(statement: &'a PolicyStatement<'a>, strict: bool) -> Resul
for policy in policies {
if !rustix::process::ksu_set_policy(&FfiPolicy::from(policy)) {
log::warn!("apply rule: {:?} failed.", statement);
log::warn!("apply rule: {statement:?} failed.");
if strict {
return Err(anyhow::anyhow!("apply rule {:?} failed.", statement));
}

View File

@@ -104,12 +104,12 @@ pub fn is_safe_mode() -> bool {
|| getprop("ro.sys.safemode")
.filter(|prop| prop == "1")
.is_some();
log::info!("safemode: {}", safemode);
log::info!("safemode: {safemode}");
if safemode {
return true;
}
let safemode = ksucalls::check_kernel_safemode();
log::info!("kernel_safemode: {}", safemode);
log::info!("kernel_safemode: {safemode}");
safemode
}

View File

@@ -348,7 +348,7 @@ pub fn restore(
do_cpio_cmd(
&magiskboot,
workdir,
&format!("extract {0} {0}", BACKUP_FILENAME),
&format!("extract {BACKUP_FILENAME} {BACKUP_FILENAME}"),
)?;
let sha = std::fs::read(workdir.join(BACKUP_FILENAME))?;
let sha = String::from_utf8(sha)?;
@@ -515,7 +515,7 @@ fn do_patch(
match get_current_kmi() {
Ok(value) => value,
Err(e) => {
println!("- {}", e);
println!("- {e}");
if let Some(image_path) = &image {
println!(
"- Trying to auto detect KMI version for {}",
@@ -713,7 +713,7 @@ fn calculate_sha1(file_path: impl AsRef<Path>) -> Result<String> {
}
let result = hasher.finalize();
Ok(format!("{:x}", result))
Ok(format!("{result:x}"))
}
#[cfg(target_os = "android")]
@@ -729,7 +729,7 @@ fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
do_cpio_cmd(
magiskboot,
workdir,
&format!("add 0755 {0} {0}", BACKUP_FILENAME),
&format!("add 0755 {BACKUP_FILENAME} {BACKUP_FILENAME}"),
)?;
println!("- Stock image has been backup to");
println!("- {target}");
@@ -739,7 +739,7 @@ fn do_backup(magiskboot: &Path, workdir: &Path, image: &str) -> Result<()> {
#[cfg(target_os = "android")]
fn clean_backup(sha1: &str) -> Result<()> {
println!("- Clean up backup");
let backup_name = format!("{}{}", KSU_BACKUP_FILE_PREFIX, sha1);
let backup_name = format!("{KSU_BACKUP_FILE_PREFIX}{sha1}");
let dir = std::fs::read_dir(defs::KSU_BACKUP_DIR)?;
for entry in dir.flatten() {
let path = entry.path();

View File

@@ -385,13 +385,13 @@ pub fn run() -> Result<()> {
Commands::BootInfo { command } => match command {
BootInfo::CurrentKmi => {
let kmi = crate::boot_patch::get_current_kmi()?;
println!("{}", kmi);
println!("{kmi}");
// return here to avoid printing the error message
return Ok(());
}
BootInfo::SupportedKmi => {
let kmi = crate::assets::list_supported_kmi()?;
kmi.iter().for_each(|kmi| println!("{}", kmi));
kmi.iter().for_each(|kmi| println!("{kmi}"));
return Ok(());
}
},
@@ -403,7 +403,7 @@ pub fn run() -> Result<()> {
};
if let Err(e) = &result {
log::error!("Error: {:?}", e);
log::error!("Error: {e:?}");
}
result
}

View File

@@ -30,7 +30,7 @@ fn set_kernel_param(uid: u32) -> Result<()> {
fn get_pkg_uid(pkg: &str) -> Result<u32> {
// stat /data/data/<pkg>
let uid = rustix::fs::stat(format!("/data/data/{pkg}"))
.with_context(|| format!("stat /data/data/{}", pkg))?
.with_context(|| format!("stat /data/data/{pkg}"))?
.st_uid;
Ok(uid)
}

View File

@@ -83,13 +83,13 @@ pub fn mount_modules_systemlessly(module_dir: &str) -> Result<()> {
// mount /system first
if let Err(e) = mount_partition("system", &system_lowerdir) {
warn!("mount system failed: {:#}", e);
warn!("mount system failed: {e:#}");
}
// mount other partitions
for (k, v) in partition_lowerdir {
if let Err(e) = mount_partition(&k, &v) {
warn!("mount {k} failed: {:#}", e);
warn!("mount {k} failed: {e:#}");
}
}
@@ -120,7 +120,7 @@ pub fn on_post_data_fs() -> Result<()> {
} else {
// Then exec common post-fs-data scripts
if let Err(e) = crate::module::exec_common_scripts("post-fs-data.d", true) {
warn!("exec common post-fs-data scripts failed: {}", e);
warn!("exec common post-fs-data scripts failed: {e}");
}
}
@@ -168,17 +168,17 @@ pub fn on_post_data_fs() -> Result<()> {
if safe_mode {
warn!("safe mode, skip post-fs-data scripts and disable all modules!");
if let Err(e) = crate::module::disable_all_modules() {
warn!("disable all modules failed: {}", e);
warn!("disable all modules failed: {e}");
}
return Ok(());
}
if let Err(e) = prune_modules() {
warn!("prune modules failed: {}", e);
warn!("prune modules failed: {e}");
}
if let Err(e) = restorecon::restorecon() {
warn!("restorecon failed: {}", e);
warn!("restorecon failed: {e}");
}
// load sepolicy.rule
@@ -187,28 +187,28 @@ pub fn on_post_data_fs() -> Result<()> {
}
if let Err(e) = crate::profile::apply_sepolies() {
warn!("apply root profile sepolicy failed: {}", e);
warn!("apply root profile sepolicy failed: {e}");
}
// mount temp dir
if let Err(e) = mount::mount_tmpfs(utils::get_tmp_path()) {
warn!("do temp dir mount failed: {}", e);
warn!("do temp dir mount failed: {e}");
}
// exec modules post-fs-data scripts
// TODO: Add timeout
if let Err(e) = crate::module::exec_stage_script("post-fs-data", true) {
warn!("exec post-fs-data scripts failed: {}", e);
warn!("exec post-fs-data scripts failed: {e}");
}
// load system.prop
if let Err(e) = crate::module::load_system_prop() {
warn!("load system.prop failed: {}", e);
warn!("load system.prop failed: {e}");
}
// mount module systemlessly by overlay
if let Err(e) = mount_modules_systemlessly(module_dir) {
warn!("do systemless mount failed: {}", e);
warn!("do systemless mount failed: {e}");
}
run_stage("post-mount", true);
@@ -298,7 +298,7 @@ fn catch_bootlog(logname: &str, command: Vec<&str>) -> Result<()> {
};
if let Err(e) = result {
warn!("Failed to start logcat: {:#}", e);
warn!("Failed to start logcat: {e:#}");
}
Ok(())

View File

@@ -274,7 +274,7 @@ pub fn prune_modules() -> Result<()> {
let uninstaller = module.join("uninstall.sh");
if uninstaller.exists() {
if let Err(e) = exec_script(uninstaller, true) {
warn!("Failed to exec uninstaller: {}", e);
warn!("Failed to exec uninstaller: {e}");
}
}
@@ -346,7 +346,7 @@ fn _install_module(zip: &str) -> Result<()> {
module_prop.insert(k, v);
},
)?;
info!("module prop: {:?}", module_prop);
info!("module prop: {module_prop:?}");
let Some(module_id) = module_prop.get("id") else {
bail!("module id not found in module.prop!");
@@ -475,13 +475,13 @@ fn _install_module(zip: &str) -> Result<()> {
let _dontdrop = mount::AutoMountExt4::try_new(tmp_module_img, module_update_tmp_dir, true)?;
info!("mounted {} to {}", tmp_module_img, module_update_tmp_dir);
info!("mounted {tmp_module_img} to {module_update_tmp_dir}");
setsyscon(module_update_tmp_dir)?;
let module_dir = format!("{module_update_tmp_dir}/{module_id}");
ensure_clean_dir(&module_dir)?;
info!("module dir: {}", module_dir);
info!("module dir: {module_dir}");
// unzip the image and move it to modules_update/<id> dir
let file = File::open(zip)?;
@@ -673,7 +673,7 @@ pub fn restore_module(id: &str) -> Result<()> {
}
pub fn run_action(id: &str) -> Result<()> {
let action_script_path = format!("/data/adb/modules/{}/action.sh", id);
let action_script_path = format!("/data/adb/modules/{id}/action.sh");
exec_script(&action_script_path, true)
}

View File

@@ -138,7 +138,7 @@ pub fn mount_overlayfs(
})();
if let Err(e) = result {
warn!("fsopen mount failed: {:#}, fallback to mount", e);
warn!("fsopen mount failed: {e:#}, fallback to mount");
let mut data = format!("lowerdir={lowerdir_config}");
if let (Some(upperdir), Some(workdir)) = (upperdir, workdir) {
data = format!("{data},upperdir={upperdir},workdir={workdir}");
@@ -246,7 +246,7 @@ fn mount_overlay_child(
}
// merge modules and stock
if let Err(e) = mount_overlayfs(&lower_dirs, stock_root, None, None, mount_point) {
warn!("failed: {:#}, fallback to bind mount", e);
warn!("failed: {e:#}, fallback to bind mount");
bind_mount(stock_root, mount_point)?;
}
Ok(())
@@ -259,7 +259,7 @@ pub fn mount_overlay(
workdir: Option<PathBuf>,
upperdir: Option<PathBuf>,
) -> Result<()> {
info!("mount overlay for {}", root);
info!("mount overlay for {root}");
std::env::set_current_dir(root).with_context(|| format!("failed to chdir to {root}"))?;
let stock_root = ".";
@@ -290,10 +290,7 @@ pub fn mount_overlay(
continue;
}
if let Err(e) = mount_overlay_child(mount_point, &relative, module_roots, &stock_root) {
warn!(
"failed to mount overlay for child {}: {:#}, revert",
mount_point, e
);
warn!("failed to mount overlay for child {mount_point}: {e:#}, revert");
umount_dir(root).with_context(|| format!("failed to revert {root}"))?;
bail!(e);
}

View File

@@ -70,9 +70,9 @@ pub fn apply_sepolies() -> Result<()> {
};
let sepolicy = sepolicy.path();
if sepolicy::apply_file(&sepolicy).is_ok() {
log::info!("profile sepolicy applied: {:?}", sepolicy);
log::info!("profile sepolicy applied: {sepolicy:?}");
} else {
log::info!("profile sepolicy apply failed: {:?}", sepolicy);
log::info!("profile sepolicy apply failed: {sepolicy:?}");
}
}
Ok(())

View File

@@ -697,7 +697,7 @@ fn apply_one_rule<'a>(statement: &'a PolicyStatement<'a>, strict: bool) -> Resul
for policy in policies {
if !rustix::process::ksu_set_policy(&FfiPolicy::from(policy)) {
log::warn!("apply rule: {:?} failed.", statement);
log::warn!("apply rule: {statement:?} failed.");
if strict {
return Err(anyhow::anyhow!("apply rule {:?} failed.", statement));
}

View File

@@ -110,12 +110,12 @@ pub fn is_safe_mode() -> bool {
|| getprop("ro.sys.safemode")
.filter(|prop| prop == "1")
.is_some();
log::info!("safemode: {}", safemode);
log::info!("safemode: {safemode}");
if safemode {
return true;
}
let safemode = ksucalls::check_kernel_safemode();
log::info!("kernel_safemode: {}", safemode);
log::info!("kernel_safemode: {safemode}");
safemode
}
@@ -240,7 +240,7 @@ pub fn get_tmp_path() -> &'static str {
CHOSEN_TMP_PATH.get_or_init(|| {
let r = find_temp_path();
log::info!("Chosen temp_path: {}", r);
log::info!("Chosen temp_path: {r}");
r
})
}
@@ -367,7 +367,7 @@ fn copy_xattrs(src_path: impl AsRef<Path>, dest_path: impl AsRef<Path>) -> Resul
if let Err(e) =
extattr::lsetxattr(dest_path.as_ref(), &xattr, &value, extattr::Flags::empty())
{
log::warn!("Failed to set xattr: {}", e);
log::warn!("Failed to set xattr: {e}");
}
}
Ok(())
@@ -400,7 +400,7 @@ pub fn copy_module_files(source: impl AsRef<Path>, destination: impl AsRef<Path>
std::fs::remove_file(&dest_path).context("Failed to remove file")?;
}
let target = std::fs::read_link(entry.path()).context("Failed to read symlink")?;
log::info!("Symlink: {:?} -> {:?}", dest_path, target);
log::info!("Symlink: {dest_path:?} -> {target:?}");
std::os::unix::fs::symlink(target, &dest_path).context("Failed to create symlink")?;
copy_xattrs(&source_path, &dest_path)?;
} else if entry.file_type().is_dir() {