From d8a8ef6458a68605ed3c8c35a487ae6dec35e72f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=94=9F=E4=BA=8E=E7=94=9F=E6=97=B6=20=E4=BA=A1=E4=BA=8E?= =?UTF-8?q?=E4=BA=A1=E5=88=BB?= <127004703+Tools-cx-app@users.noreply.github.com> Date: Sat, 8 Nov 2025 12:34:22 +0800 Subject: [PATCH] fix: fix self exe path error && opt: Optimize ensure_dir_exists processing (#541) * fix: fix self exe path error * opt: Optimize ensure_dir_exists processing --------- Signed-off-by: Tools-app --- userspace/ksud/src/utils.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/userspace/ksud/src/utils.rs b/userspace/ksud/src/utils.rs index 68a13728..f1262656 100644 --- a/userspace/ksud/src/utils.rs +++ b/userspace/ksud/src/utils.rs @@ -45,13 +45,11 @@ pub fn ensure_file_exists>(file: T) -> Result<()> { } pub fn ensure_dir_exists>(dir: T) -> Result<()> { - let result = create_dir_all(&dir).map_err(Error::from); - if dir.as_ref().is_dir() { - result - } else if result.is_ok() { - bail!("{} is not a regular directory", dir.as_ref().display()) + let result = create_dir_all(&dir); + if dir.as_ref().is_dir() && result.is_err() { + Ok(()) } else { - result + bail!("{} is not a regular directory", dir.as_ref().display()) } } @@ -207,7 +205,10 @@ fn link_ksud_to_bin() -> Result<()> { pub fn install(magiskboot: Option) -> Result<()> { ensure_dir_exists(defs::ADB_DIR)?; - std::fs::copy("/proc/self/exe", defs::DAEMON_PATH)?; + std::fs::copy( + std::env::current_exe().with_context(|| "Failed to get self exe path")?, + defs::DAEMON_PATH, + )?; restorecon::lsetfilecon(defs::DAEMON_PATH, restorecon::ADB_CON)?; // install binary assets assets::ensure_binaries(false).with_context(|| "Failed to extract assets")?;