Skip to content

Commit

Permalink
fix: skip needrestart when using nala on debian-based distro
Browse files Browse the repository at this point in the history
  • Loading branch information
SteveLauC committed Sep 14, 2023
1 parent b814dd8 commit 5343f8e
Showing 1 changed file with 44 additions and 5 deletions.
49 changes: 44 additions & 5 deletions src/steps/os/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ impl Distribution {
}
} else {
Ok(Distribution::Fedora)
}
};
}

Some("void") => Distribution::Void,
Expand Down Expand Up @@ -317,6 +317,7 @@ fn upgrade_openmandriva(ctx: &ExecutionContext) -> Result<()> {

Ok(())
}

fn upgrade_pclinuxos(ctx: &ExecutionContext) -> Result<()> {
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
let mut command_update = ctx.run_type().execute(sudo);
Expand Down Expand Up @@ -708,15 +709,53 @@ fn upgrade_neon(ctx: &ExecutionContext) -> Result<()> {
Ok(())
}

pub fn run_needrestart(ctx: &ExecutionContext) -> Result<()> {
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
let needrestart = require("needrestart")?;
/// `needrestart` should be skipped if:
///
/// 1. This is a redhat-based distribution
/// 2. This is a debian-based distribution and it is using `nala` as the `apt`
/// alternative
fn should_skip_needrestart() -> Result<()> {
let distribution = Distribution::detect()?;
let msg = "needrestart will be ran by the package manager";

if distribution.redhat_based() {
return Err(SkipStep(String::from("needrestart will be ran by the package manager")).into());
return Err(SkipStep(String::from(msg)).into());
}

if matches!(distribution, Distribution::Debian) {
let apt = which("apt-fast")
.or_else(|| {
if which("mist").is_some() {
Some(PathBuf::from("mist"))
} else {
None
}
})
.or_else(|| {
if Path::new("/usr/bin/nala").exists() {
Some(Path::new("/usr/bin/nala").to_path_buf())
} else {
None
}
})
.unwrap_or_else(|| PathBuf::from("apt-get"));

let is_nala = apt.ends_with("nala");

if is_nala {
return Err(SkipStep(String::from(msg)).into());
}
}

Ok(())
}

pub fn run_needrestart(ctx: &ExecutionContext) -> Result<()> {
let sudo = require_option(ctx.sudo().as_ref(), REQUIRE_SUDO.to_string())?;
let needrestart = require("needrestart")?;

should_skip_needrestart()?;

print_separator("Check for needed restarts");

ctx.run_type().execute(sudo).arg(needrestart).status_checked()?;
Expand Down

0 comments on commit 5343f8e

Please sign in to comment.