Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ksud: extract binaries properly #1253

Merged
merged 2 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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(true).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
11 changes: 9 additions & 2 deletions userspace/ksud/src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::{bail, Context, Error, Ok, Result};
use std::{
fs::{create_dir_all, write, File, OpenOptions},
io::{ErrorKind::AlreadyExists, Write},
fs::{create_dir_all, remove_file, write, File, OpenOptions},
io::{ErrorKind::AlreadyExists, ErrorKind::NotFound, Write},
path::Path,
};

Expand Down Expand Up @@ -63,6 +63,13 @@ pub fn ensure_binary<T: AsRef<Path>>(
)
})?)?;

if let Err(e) = remove_file(path.as_ref()) {
if e.kind() != NotFound {
return Err(Error::from(e))
.with_context(|| format!("failed to unlink {}", path.as_ref().display()));
}
}

write(&path, contents)?;
#[cfg(unix)]
set_permissions(&path, Permissions::from_mode(0o755))?;
Expand Down
Loading