ksud: make clippy happy (#2683)

e1be06240d/clippy_lints/src/format_args.rs (L168)
This commit is contained in:
5ec1cff
2025-07-18 17:10:40 +08:00
committed by GitHub
parent ee72b8e106
commit 6c61a8b7c7
11 changed files with 59 additions and 84 deletions

View File

@@ -483,17 +483,6 @@ dependencies = [
"crypto-common",
]
[[package]]
name = "displaydoc"
version = "0.2.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97369cbbc041bc366949bc74d34658d6cda5621039731c6310521892a3a20ae0"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "either"
version = "1.15.0"
@@ -595,6 +584,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7ced92e76e966ca2fd84c8f7aa01a4aea65b0eb6648d72f7c8f3e2764a67fece"
dependencies = [
"crc32fast",
"libz-rs-sys",
"miniz_oxide",
]
@@ -682,7 +672,7 @@ dependencies = [
"errno 0.2.8",
"libc",
"memmap",
"thiserror 1.0.69",
"thiserror",
"winapi",
]
@@ -883,6 +873,15 @@ version = "0.2.15"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f9fbbcab51052fe104eb5e5d351cf728d30a5be1fe14d9be8a3b097481fb97de"
[[package]]
name = "libz-rs-sys"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "172a788537a2221661b480fee8dc5f96c580eb34fa88764d3205dc356c7e4221"
dependencies = [
"zlib-rs",
]
[[package]]
name = "linux-raw-sys"
version = "0.4.15"
@@ -1311,16 +1310,7 @@ version = "1.0.69"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52"
dependencies = [
"thiserror-impl 1.0.69",
]
[[package]]
name = "thiserror"
version = "2.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d452f284b73e6d76dd36758a0c8684b1d5be31f92b89d07fd5822175732206fc"
dependencies = [
"thiserror-impl 2.0.11",
"thiserror-impl",
]
[[package]]
@@ -1334,17 +1324,6 @@ dependencies = [
"syn",
]
[[package]]
name = "thiserror-impl"
version = "2.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "26afc1baea8a989337eeb52b6e72a039780ce45c3edfcc9c5b9d112feeb173c2"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "time"
version = "0.3.41"
@@ -1725,12 +1704,10 @@ dependencies = [
"arbitrary",
"crc32fast",
"deflate64",
"displaydoc",
"flate2",
"indexmap",
"lzma-rs",
"memchr",
"thiserror 2.0.11",
"time",
"xz2",
"zopfli",
@@ -1745,6 +1722,12 @@ dependencies = [
"zip",
]
[[package]]
name = "zlib-rs"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "626bd9fa9734751fc50d6060752170984d7053f5a39061f524cda68023d4db8a"
[[package]]
name = "zopfli"
version = "0.8.2"

View File

@@ -14,7 +14,7 @@ fn get_git_version() -> Result<(u32, String), std::io::Error> {
let version_code: u32 = version_code
.trim()
.parse()
.map_err(|_| std::io::Error::new(std::io::ErrorKind::Other, "Failed to parse git count"))?;
.map_err(|_| std::io::Error::other("Failed to parse git count"))?;
let version_code = 10000 + 200 + version_code; // For historical reasons
let version_name = String::from_utf8(
@@ -23,12 +23,7 @@ fn get_git_version() -> Result<(u32, String), std::io::Error> {
.output()?
.stdout,
)
.map_err(|_| {
std::io::Error::new(
std::io::ErrorKind::Other,
"Failed to read git describe stdout",
)
})?;
.map_err(|_| std::io::Error::other("Failed to read git describe stdout"))?;
let version_name = version_name.trim_start_matches('v').to_string();
Ok((version_code, version_name))
}

View File

@@ -245,7 +245,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)?;
@@ -384,7 +384,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 {}",
@@ -542,7 +542,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")]
@@ -558,7 +558,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}");
@@ -568,7 +568,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

@@ -374,13 +374,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(());
}
},
@@ -392,7 +392,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(defs::TEMP_DIR) {
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

@@ -268,7 +268,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}");
}
}
@@ -341,7 +341,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!");
@@ -440,13 +440,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)?;
@@ -584,7 +584,7 @@ pub fn uninstall_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)
}
@@ -674,11 +674,11 @@ fn _list_modules(path: &str) -> Vec<HashMap<String, String>> {
if !module_prop_map.contains_key("id") || module_prop_map["id"].is_empty() {
match entry.file_name().to_str() {
Some(id) => {
info!("Use dir name as module id: {}", id);
info!("Use dir name as module id: {id}");
module_prop_map.insert("id".to_owned(), id.to_owned());
}
_ => {
info!("Failed to get module id: {:?}", module_prop);
info!("Failed to get module id: {module_prop:?}");
continue;
}
}

View File

@@ -135,7 +135,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}");
@@ -225,7 +225,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(())
@@ -238,7 +238,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 = ".";
@@ -269,10 +269,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

@@ -108,12 +108,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
}
@@ -303,7 +303,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(())
@@ -336,7 +336,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() {