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 <localhost.hutao@gmail.com>
This commit is contained in:
@@ -45,13 +45,11 @@ pub fn ensure_file_exists<T: AsRef<Path>>(file: T) -> Result<()> {
|
||||
}
|
||||
|
||||
pub fn ensure_dir_exists<T: AsRef<Path>>(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<PathBuf>) -> 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")?;
|
||||
|
||||
Reference in New Issue
Block a user