Skip to content
Draft
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
15 changes: 8 additions & 7 deletions src/action/linux/provision_selinux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,9 @@ impl Action for ProvisionSelinux {

#[tracing::instrument(level = "debug", skip_all)]
async fn execute(&mut self) -> Result<(), ActionError> {
if self.policy_path.exists() {
// Rebuild it.
remove_existing_policy(&self.policy_path)
.await
.map_err(Self::error)?;
}
remove_existing_policy(&self.policy_path)
.await
.map_err(Self::error)?;

if let Some(parent) = self.policy_path.parent() {
tokio::fs::create_dir_all(&parent)
Expand Down Expand Up @@ -123,7 +120,11 @@ impl Action for ProvisionSelinux {
}

async fn remove_existing_policy(policy_path: &Path) -> Result<(), ActionErrorKind> {
execute_command(Command::new("semodule").arg("--remove").arg("nix")).await?;
let output = execute_command(Command::new("semodule").arg("--list-modules=standard")).await?;
let stdout = String::from_utf8_lossy(&output.stdout);
if stdout.lines().any(|line| line == "nix") {
execute_command(Command::new("semodule").arg("--remove").arg("nix")).await?;
}

crate::util::remove_file(policy_path, OnMissing::Ignore)
.await
Expand Down
Loading