diff --git a/userspace/ksud/src/defs.rs b/userspace/ksud/src/defs.rs index 44f193aeb5d8..a8543030560b 100644 --- a/userspace/ksud/src/defs.rs +++ b/userspace/ksud/src/defs.rs @@ -25,7 +25,6 @@ pub const MODULE_UPDATE_DIR: &str = concatcp!(ADB_DIR, "modules_update/"); pub const KSUD_VERBOSE_LOG_FILE: &str = concatcp!(ADB_DIR, "verbose"); pub const TEMP_DIR: &str = "/debug_ramdisk"; -pub const TEMP_DIR_LEGACY: &str = "/sbin"; pub const MODULE_WEB_DIR: &str = "webroot"; pub const MODULE_ACTION_SH: &str = "action.sh"; diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs index 6231353b1e59..0ca3791c44a9 100644 --- a/userspace/ksud/src/utils.rs +++ b/userspace/ksud/src/utils.rs @@ -185,68 +185,6 @@ pub fn has_magisk() -> bool { which::which("magisk").is_ok() } -fn is_ok_empty(dir: &str) -> bool { - use std::result::Result::Ok; - - match fs::read_dir(dir) { - Ok(mut entries) => entries.next().is_none(), - Err(_) => false, - } -} - -fn find_temp_path() -> String { - use std::result::Result::Ok; - - if is_ok_empty(defs::TEMP_DIR) { - return defs::TEMP_DIR.to_string(); - } - - // Try to create a random directory in /dev/ - let r = tempdir::TempDir::new_in("/dev/", ""); - match r { - Ok(tmp_dir) => { - if let Some(path) = tmp_dir.into_path().to_str() { - return path.to_string(); - } - } - Err(_e) => {} - } - - let dirs = [ - defs::TEMP_DIR, - "/patch_hw", - "/oem", - "/root", - defs::TEMP_DIR_LEGACY, - ]; - - // find empty directory - for dir in dirs { - if is_ok_empty(dir) { - return dir.to_string(); - } - } - - // Fallback to non-empty directory - for dir in dirs { - if metadata(dir).is_ok() { - return dir.to_string(); - } - } - - "".to_string() -} - -pub fn get_tmp_path() -> &'static str { - static CHOSEN_TMP_PATH: OnceLock = OnceLock::new(); - - CHOSEN_TMP_PATH.get_or_init(|| { - let r = find_temp_path(); - log::info!("Chosen temp_path: {}", r); - r - }) -} - #[cfg(target_os = "android")] fn link_ksud_to_bin() -> Result<()> { let ksu_bin = PathBuf::from(defs::DAEMON_PATH);