feat: Optimize some codes (ksud) (#465)
* chore: make cargo clippy happy Signed-off-by: Tools-app <localhost.hutao@gmail.com> * chore: Optimize import - Format as a standard import Signed-off-by: Tools-app <localhost.hutao@gmail.com> --------- Signed-off-by: Tools-app <localhost.hutao@gmail.com>
This commit is contained in:
@@ -1,22 +1,19 @@
|
||||
#[cfg(unix)]
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
use std::path::Path;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
use std::process::Stdio;
|
||||
use std::{
|
||||
os::unix::fs::PermissionsExt,
|
||||
path::{Path, PathBuf},
|
||||
process::{Command, Stdio},
|
||||
};
|
||||
|
||||
use anyhow::Context;
|
||||
use anyhow::Result;
|
||||
use anyhow::anyhow;
|
||||
use anyhow::bail;
|
||||
use anyhow::ensure;
|
||||
use anyhow::{Context, Result, anyhow, bail, ensure};
|
||||
use regex_lite::Regex;
|
||||
use which::which;
|
||||
|
||||
use crate::defs;
|
||||
use crate::defs::BACKUP_FILENAME;
|
||||
use crate::defs::{KSU_BACKUP_DIR, KSU_BACKUP_FILE_PREFIX};
|
||||
use crate::{assets, utils};
|
||||
use crate::{
|
||||
assets,
|
||||
defs::{self, BACKUP_FILENAME, KSU_BACKUP_DIR, KSU_BACKUP_FILE_PREFIX},
|
||||
utils,
|
||||
};
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
fn ensure_gki_kernel() -> Result<()> {
|
||||
@@ -118,11 +115,11 @@ fn parse_kmi_from_kernel(kernel: &PathBuf, workdir: &Path) -> Result<String> {
|
||||
let re =
|
||||
Regex::new(r"(?:.* )?(\d+\.\d+)(?:\S+)?(android\d+)").context("Failed to compile regex")?;
|
||||
for s in printable_strings {
|
||||
if let Some(caps) = re.captures(s) {
|
||||
if let (Some(kernel_version), Some(android_version)) = (caps.get(1), caps.get(2)) {
|
||||
let kmi = format!("{}-{}", android_version.as_str(), kernel_version.as_str());
|
||||
return Ok(kmi);
|
||||
}
|
||||
if let Some(caps) = re.captures(s)
|
||||
&& let (Some(kernel_version), Some(android_version)) = (caps.get(1), caps.get(2))
|
||||
{
|
||||
let kmi = format!("{}-{}", android_version.as_str(), kernel_version.as_str());
|
||||
return Ok(kmi);
|
||||
}
|
||||
}
|
||||
println!("- Failed to get KMI version");
|
||||
@@ -711,10 +708,8 @@ fn do_patch(
|
||||
}
|
||||
|
||||
#[cfg(target_os = "android")]
|
||||
if need_backup {
|
||||
if let Err(e) = do_backup(&magiskboot, workdir, &bootimage) {
|
||||
println!("- Backup stock image failed: {e}");
|
||||
}
|
||||
if need_backup && let Err(e) = do_backup(&magiskboot, workdir, &bootimage) {
|
||||
println!("- Backup stock image failed: {e}");
|
||||
}
|
||||
|
||||
println!("- Repacking boot image");
|
||||
@@ -951,16 +946,15 @@ fn find_boot_image(
|
||||
&& !is_replace_kernel
|
||||
&& vendor_boot_exist
|
||||
&& !skip_init
|
||||
{
|
||||
if unpack_and_check_init(
|
||||
&& unpack_and_check_init(
|
||||
magiskboot,
|
||||
workdir,
|
||||
&vendor_boot_partition,
|
||||
"vendor_ramdisk/init_boot.cpio",
|
||||
)? {
|
||||
println!("- Using vendor_boot partition (vendor_ramdisk/init_boot.cpio).");
|
||||
selected_partition = &vendor_boot_partition;
|
||||
}
|
||||
)?
|
||||
{
|
||||
println!("- Using vendor_boot partition (vendor_ramdisk/init_boot.cpio).");
|
||||
selected_partition = &vendor_boot_partition;
|
||||
}
|
||||
|
||||
// try vendor_boot/vendor_ramdisk/ramdisk.cpio
|
||||
@@ -968,16 +962,15 @@ fn find_boot_image(
|
||||
&& !is_replace_kernel
|
||||
&& vendor_boot_exist
|
||||
&& !skip_init
|
||||
{
|
||||
if unpack_and_check_init(
|
||||
&& unpack_and_check_init(
|
||||
magiskboot,
|
||||
workdir,
|
||||
&vendor_boot_partition,
|
||||
"vendor_ramdisk/ramdisk.cpio",
|
||||
)? {
|
||||
println!("- Using vendor_boot partition (vendor_ramdisk/ramdisk.cpio).");
|
||||
selected_partition = &vendor_boot_partition;
|
||||
}
|
||||
)?
|
||||
{
|
||||
println!("- Using vendor_boot partition (vendor_ramdisk/ramdisk.cpio).");
|
||||
selected_partition = &vendor_boot_partition;
|
||||
}
|
||||
|
||||
if selected_partition == &boot_partition {
|
||||
@@ -1034,4 +1027,4 @@ rm -f /data/adb/post-fs-data.d/post_ota.sh
|
||||
std::fs::set_permissions(post_ota_sh, std::fs::Permissions::from_mode(0o755))?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user