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

fix: skip needrestart when using nala on debian-based distro #548

Merged
merged 1 commit into from
Sep 14, 2023
Merged
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
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