Skip to content

Commit

Permalink
ksud: re-extract ksud when necessary close #1242
Browse files Browse the repository at this point in the history
  • Loading branch information
tiann committed Jan 4, 2024
1 parent 097e291 commit b99701d
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 6 deletions.
3 changes: 2 additions & 1 deletion userspace/ksud/src/assets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ struct Asset;
#[folder = "bin/x86_64"]
struct Asset;

pub fn ensure_binaries() -> Result<()> {
pub fn ensure_binaries(ignore_if_exist: bool) -> Result<()> {
for file in Asset::iter() {
utils::ensure_binary(
format!("{BINARY_DIR}{file}"),
&Asset::get(&file).unwrap().data,
ignore_if_exist,
)?
}
Ok(())
Expand Down
4 changes: 2 additions & 2 deletions userspace/ksud/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ pub fn on_post_data_fs() -> Result<()> {
// we should clean the module mount point if it exists
ensure_clean_dir(module_dir)?;

assets::ensure_binaries().with_context(|| "Failed to extract bin assets")?;
assets::ensure_binaries(true).with_context(|| "Failed to extract bin assets")?;

if Path::new(module_update_img).exists() {
if module_update_flag.exists() {
Expand Down Expand Up @@ -259,7 +259,7 @@ pub fn install() -> Result<()> {
std::fs::copy("/proc/self/exe", defs::DAEMON_PATH)?;
restorecon::lsetfilecon(defs::DAEMON_PATH, restorecon::ADB_CON)?;
// install binary assets
assets::ensure_binaries().with_context(|| "Failed to extract assets")?;
assets::ensure_binaries(false).with_context(|| "Failed to extract assets")?;

#[cfg(target_os = "android")]
link_ksud_to_bin()?;
Expand Down
2 changes: 1 addition & 1 deletion userspace/ksud/src/module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ fn _install_module(zip: &str) -> Result<()> {
// print banner
println!(include_str!("banner"));

assets::ensure_binaries().with_context(|| "Failed to extract assets")?;
assets::ensure_binaries(false).with_context(|| "Failed to extract assets")?;

// first check if workding dir is usable
ensure_dir_exists(defs::WORKING_DIR).with_context(|| "Failed to create working dir")?;
Expand Down
4 changes: 2 additions & 2 deletions userspace/ksud/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ pub fn ensure_dir_exists<T: AsRef<Path>>(dir: T) -> Result<()> {
}
}

pub fn ensure_binary<T: AsRef<Path>>(path: T, contents: &[u8]) -> Result<()> {
if path.as_ref().exists() {
pub fn ensure_binary<T: AsRef<Path>>(path: T, contents: &[u8], ignore_if_exist: bool) -> Result<()> {
if ignore_if_exist && path.as_ref().exists() {
return Ok(());
}

Expand Down

0 comments on commit b99701d

Please sign in to comment.