Skip to content

Commit

Permalink
fixup! Use dpkg to install app instead of apt
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkusPettersson98 committed Nov 4, 2024
1 parent c2520a5 commit 478fcb3
Showing 1 changed file with 7 additions and 33 deletions.
40 changes: 7 additions & 33 deletions test/test-runner/src/package.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ pub async fn install_package(package: Package) -> Result<()> {
#[cfg(target_os = "linux")]
pub async fn install_package(package: Package) -> Result<()> {
match get_distribution()? {
Distribution::Debian | Distribution::Ubuntu => install_dpkg(&package.path).await,
Distribution::Debian | Distribution::Ubuntu => install_apt(&package.path).await,
Distribution::Fedora => install_rpm(&package.path).await,
}
}
Expand All @@ -126,38 +126,6 @@ pub async fn install_package(package: Package) -> Result<()> {
.and_then(|output| result_from_output("installer -pkg", output))
}

/// We prefer to use `dpkg` to install packages as `apt` could sporadically consider installing a
/// development build to be a downgrade from the baseline stable version.
#[cfg(target_os = "linux")]
async fn install_dpkg(path: &Path) -> Result<()> {
let path = path.to_str().unwrap();
let mut cmd = Command::new("/usr/bin/dpkg");
// Workaround for forcing `dpkg` to install a package non-interactively: https://stackoverflow.com/a/45349673
let yes: Stdio = {
let mut yes = Command::new("/usr/bin/yes");
yes.stdout(Stdio::piped());
let yes = yes.spawn().expect("Failed to spawn `yes` command");
// There is not really an ergonomic way to pipe stdout from tokio command
// into another tokio command..: https://github.com/tokio-rs/tokio/discussions/3447
yes.stdout
.expect("Failed to take stdout from `yes` command")
.try_into()
.unwrap()
};
// I.e. pipe `yes` into `dpkg`.
cmd.stdin(yes);
cmd.args(["--install", path]);
// Don't fail due to the global apt lock being held, which happens sporadically.
cmd.args(["DPKG_FRONTEND_LOCKED", "0"]);

cmd.spawn()
.map_err(|e| strip_error(Error::RunApp, e))?
.wait_with_output()
.await
.map_err(|e| strip_error(Error::RunApp, e))
.and_then(|output| result_from_output("dpkg", output))
}

#[cfg(target_os = "linux")]
async fn install_apt(path: &Path) -> Result<()> {
let mut cmd = apt_command();
Expand Down Expand Up @@ -205,6 +173,12 @@ fn apt_command() -> Command {
// instead.
cmd.args(["-o", "DPkg::Lock::Timeout=60"]);
cmd.arg("-qy");
// `apt` may sporadically consider installing a development build to be a downgrade from the baseline stable
// version, which is why we pass this flag.
//
// Note that this is only sound if we take precaution to check the installed version after
// running this command.
cmd.arg("--allow-downgrades");

cmd.env("DEBIAN_FRONTEND", "noninteractive");

Expand Down

0 comments on commit 478fcb3

Please sign in to comment.