From d55dfe79dd47cf31d9d0fc7747f94b54fb54be2c Mon Sep 17 00:00:00 2001 From: LoveSy Date: Thu, 15 Aug 2024 16:28:05 +0800 Subject: [PATCH] Use tempfile (#1980) --- userspace/ksud/Cargo.lock | 102 +++++++++++-------------------- userspace/ksud/Cargo.toml | 32 +++++----- userspace/ksud/src/boot_patch.rs | 10 ++- userspace/ksud/src/utils.rs | 2 +- 4 files changed, 59 insertions(+), 87 deletions(-) diff --git a/userspace/ksud/Cargo.lock b/userspace/ksud/Cargo.lock index 262a61a495d0..369e1e421423 100644 --- a/userspace/ksud/Cargo.lock +++ b/userspace/ksud/Cargo.lock @@ -115,7 +115,7 @@ version = "1.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6d36fc52c7f6c869915e99412912f22093507da8d9e942ceaf66fe4b7c14422a" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -125,7 +125,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5bf74e1b6e971609db8ca7a9ce79fd5768ab6ae46441c572e46cf596f59e57f8" dependencies = [ "anstyle", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -551,7 +551,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "534c5cf6194dfab3db3242765c03bbe257cf92f22b38f6bc0c58d59108a820ba" dependencies = [ "libc", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -575,6 +575,12 @@ dependencies = [ "libc", ] +[[package]] +name = "fastrand" +version = "2.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fc0510504f03c51ada170672ac806f1f105a88aa97a5281117e1ddc3368e51a" + [[package]] name = "flate2" version = "1.0.31" @@ -585,12 +591,6 @@ dependencies = [ "miniz_oxide", ] -[[package]] -name = "fuchsia-cprng" -version = "0.1.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a06f77d526c1a601b7c4cdd98f54b5eaabffc14d5f2f0296febdc7f357c6d3ba" - [[package]] name = "generic-array" version = "0.14.7" @@ -668,7 +668,7 @@ version = "0.5.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e3d1354bf6b7235cb4a0576c2619fd4ed18183f689b12b006a0ee7329eeff9a5" dependencies = [ - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -819,7 +819,7 @@ dependencies = [ "serde_json", "sha1", "sha256", - "tempdir", + "tempfile", "which", "zip", "zip-extensions", @@ -1040,19 +1040,6 @@ dependencies = [ "proc-macro2", ] -[[package]] -name = "rand" -version = "0.4.6" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "552840b97013b1a26992c11eac34bdd778e464601a4c2054b5f0bff7c6761293" -dependencies = [ - "fuchsia-cprng", - "libc", - "rand_core 0.3.1", - "rdrand", - "winapi", -] - [[package]] name = "rand" version = "0.8.5" @@ -1061,7 +1048,7 @@ checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404" dependencies = [ "libc", "rand_chacha", - "rand_core 0.6.4", + "rand_core", ] [[package]] @@ -1071,24 +1058,9 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88" dependencies = [ "ppv-lite86", - "rand_core 0.6.4", -] - -[[package]] -name = "rand_core" -version = "0.3.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7a6fdeb83b075e8266dcc8762c22776f6877a63111121f5f8c7411e5be7eed4b" -dependencies = [ - "rand_core 0.4.2", + "rand_core", ] -[[package]] -name = "rand_core" -version = "0.4.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c33a3c44ca05fa6f1807d8e6743f3824e8509beca625669633be0acbdf509dc" - [[package]] name = "rand_core" version = "0.6.4" @@ -1118,37 +1090,19 @@ dependencies = [ "crossbeam-utils", ] -[[package]] -name = "rdrand" -version = "0.4.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "678054eb77286b51581ba43620cc911abf02758c91f93f479767aed0f90458b2" -dependencies = [ - "rand_core 0.3.1", -] - [[package]] name = "regex-lite" version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "53a49587ad06b26609c52e423de037e7f57f20d53535d66e08c695f347df952a" -[[package]] -name = "remove_dir_all" -version = "0.5.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3acd125665422973a33ac9d3dd2df85edad0f4ae9b00dafb1a05e43a9f5ef8e7" -dependencies = [ - "winapi", -] - [[package]] name = "retry" version = "2.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9166d72162de3575f950507683fac47e30f6f2c3836b71b7fbc61aa517c9c5f4" dependencies = [ - "rand 0.8.5", + "rand", ] [[package]] @@ -1208,7 +1162,7 @@ dependencies = [ "errno 0.3.9", "libc", "linux-raw-sys", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1222,7 +1176,7 @@ dependencies = [ "libc", "linux-raw-sys", "once_cell", - "windows-sys", + "windows-sys 0.52.0", ] [[package]] @@ -1337,13 +1291,16 @@ dependencies = [ ] [[package]] -name = "tempdir" -version = "0.3.7" +name = "tempfile" +version = "3.12.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "15f2b5fb00ccdf689e0149d1b1b3c03fead81c2b37735d812fa8bddbbf41b6d8" +checksum = "04cbcdd0c794ebb0d4cf35e88edd2f7d2c4c3e9a5a6dab322839b321c6a87a64" dependencies = [ - "rand 0.4.6", - "remove_dir_all", + "cfg-if 1.0.0", + "fastrand", + "once_cell", + "rustix 0.38.34 (registry+https://github.com/rust-lang/crates.io-index)", + "windows-sys 0.59.0", ] [[package]] @@ -1537,7 +1494,7 @@ version = "0.1.9" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "cf221c93e13a30d793f7645a0e7762c55d169dbb0a49671918a2319d289b10bb" dependencies = [ - "windows-sys", + "windows-sys 0.59.0", ] [[package]] @@ -1564,6 +1521,15 @@ dependencies = [ "windows-targets", ] +[[package]] +name = "windows-sys" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e38bc4d79ed67fd075bcc251a1c39b32a1776bbe92e5bef1f0bf1f8c531853b" +dependencies = [ + "windows-targets", +] + [[package]] name = "windows-targets" version = "0.52.6" diff --git a/userspace/ksud/Cargo.toml b/userspace/ksud/Cargo.toml index 3e6545dd38fd..5a4068a5c00c 100644 --- a/userspace/ksud/Cargo.toml +++ b/userspace/ksud/Cargo.toml @@ -2,16 +2,15 @@ name = "ksud" version = "0.1.0" edition = "2021" -rust-version = "1.77.2" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -anyhow = "1" -clap = { version = "4", features = ["derive"] } +anyhow = "1.0" +clap = { version = "4.5", features = ["derive"] } const_format = "0.2" -zip = { version = "2.1.6", default-features = false } -zip-extensions = { version = "0.8.1", features = [ +zip = { version = "2.1", default-features = false } +zip-extensions = { version = "0.8", features = [ "deflate", "deflate64", "time", @@ -21,29 +20,29 @@ zip-extensions = { version = "0.8.1", features = [ java-properties = { git = "https://github.com/Kernel-SU/java-properties.git", branch = "master", default-features = false } log = "0.4" env_logger = { version = "0.11", default-features = false } -serde = { version = "1" } -serde_json = "1" +serde = { version = "1.0" } +serde_json = "1.0" encoding_rs = "0.8" -retry = "2" -humansize = "2" +retry = "2.0" +humansize = "2.1" libc = "0.2" -extattr = "1" +extattr = "1.0" jwalk = "0.8" -is_executable = "1" -nom = "7" +is_executable = "1.0" +nom = "7.1" derive-new = "0.6" -rust-embed = { version = "8", features = [ +rust-embed = { version = "8.5", features = [ "debug-embed", "compression", # must clean build after updating binaries ] } -which = "6" +which = "6.0" getopts = "0.2" sha256 = "1" sha1 = "0.10" -tempdir = "0.3" +tempfile = "3.12" chrono = "0.4" hole-punch = { git = "https://github.com/tiann/hole-punch" } -regex-lite = "0.1.6" +regex-lite = "0.1" [target.'cfg(any(target_os = "android", target_os = "linux"))'.dependencies] rustix = { git = "https://github.com/Kernel-SU/rustix.git", branch = "main", features = [ @@ -61,3 +60,4 @@ android_logger = { version = "0.14", default-features = false } strip = true opt-level = "z" lto = true +codegen-units = 1 diff --git a/userspace/ksud/src/boot_patch.rs b/userspace/ksud/src/boot_patch.rs index a303e03091e4..8ce6ee73a186 100644 --- a/userspace/ksud/src/boot_patch.rs +++ b/userspace/ksud/src/boot_patch.rs @@ -211,7 +211,10 @@ pub fn restore( magiskboot_path: Option, flash: bool, ) -> Result<()> { - let tmpdir = tempdir::TempDir::new("KernelSU").context("create temp dir failed")?; + let tmpdir = tempfile::Builder::new() + .prefix("KernelSU") + .tempdir() + .context("create temp dir failed")?; let workdir = tmpdir.path(); let magiskboot = find_magiskboot(magiskboot_path, workdir)?; @@ -366,7 +369,10 @@ fn do_patch( ); } - let tmpdir = tempdir::TempDir::new("KernelSU").context("create temp dir failed")?; + let tmpdir = tempfile::Builder::new() + .prefix("KernelSU") + .tempdir() + .context("create temp dir failed")?; let workdir = tmpdir.path(); // extract magiskboot diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs index 9bacfa366496..f7e695507be1 100644 --- a/userspace/ksud/src/utils.rs +++ b/userspace/ksud/src/utils.rs @@ -206,7 +206,7 @@ fn find_temp_path() -> String { } // Try to create a random directory in /dev/ - let r = tempdir::TempDir::new_in("/dev/", ""); + let r = tempfile::tempdir_in("/dev/"); match r { Ok(tmp_dir) => { if let Some(path) = tmp_dir.into_path().to_str() {