From 7e6ba6714e377cb655fd839576c1c1118f7ab4ea Mon Sep 17 00:00:00 2001 From: eatradish Date: Thu, 20 Feb 2025 21:59:00 +0800 Subject: [PATCH] fix(oma-pm): check `dpkg --configure` and `dpkg --triggers-only` exit status --- oma-pm/src/apt.rs | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/oma-pm/src/apt.rs b/oma-pm/src/apt.rs index 3ea5bb81..18d9fff9 100644 --- a/oma-pm/src/apt.rs +++ b/oma-pm/src/apt.rs @@ -692,14 +692,7 @@ impl OmaApt { .spawn() .map_err(OmaAptError::DpkgFailedConfigure)?; - if let Err(e) = cmd.wait_with_output() { - return Err(OmaAptError::DpkgFailedConfigure(io::Error::new( - ErrorKind::Other, - format!("dpkg return non-zero code: {:?}", e), - ))); - } - - Ok(()) + dpkg_exit_status(cmd) } pub(crate) fn run_dpkg_triggers(&self) -> OmaAptResult<()> { @@ -713,14 +706,7 @@ impl OmaApt { .spawn() .map_err(OmaAptError::DpkgFailedConfigure)?; - if let Err(e) = cmd.wait_with_output() { - return Err(OmaAptError::DpkgTriggers(io::Error::new( - ErrorKind::Other, - format!("dpkg return non-zero code: {:?}", e), - ))); - } - - Ok(()) + dpkg_exit_status(cmd) } /// Get apt archive dir @@ -1160,6 +1146,30 @@ impl OmaApt { } } +fn dpkg_exit_status(mut cmd: std::process::Child) -> Result<(), OmaAptError> { + match cmd.wait() { + Ok(status) => match status.code() { + Some(0) => Ok(()), + Some(x) => { + return Err(OmaAptError::DpkgFailedConfigure(io::Error::new( + ErrorKind::Other, + format!("dpkg return non-zero code: {}", x), + ))) + } + None => { + return Err(OmaAptError::DpkgFailedConfigure(io::Error::new( + ErrorKind::Other, + "Could not get dpkg exit status", + ))); + } + }, + Err(e) => Err(OmaAptError::DpkgFailedConfigure(io::Error::new( + ErrorKind::Other, + e, + ))), + } +} + fn get_package_url(cand: &Version<'_>) -> Vec { let uri = cand .version_files()