Skip to content

Commit ffddbb7

Browse files
committed
fix: use dpkg-query to check for installs
Before this commit, `oxidizr` checked if packages were installed by checking for the word `installed` in the output of `apt list <pkg>`, which works fine all the time `apt` is in English, but not so well if the system uses a different locale. This commit instead relies upon `dpkg-query -s`, which fails if the package is not installed.
1 parent dd03c70 commit ffddbb7

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/utils/worker.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,11 @@ pub trait Worker {
5757

5858
/// Check if a package is installed using the system package manager.
5959
fn check_installed(&self, package: &str) -> Result<bool> {
60-
let cmd = Command::build("apt", &["list", package]);
61-
let output = self.run(&cmd)?;
62-
let output = String::from_utf8(output.stdout)?.to_string();
63-
Ok(output.contains("installed"))
60+
let cmd = Command::build("dpkg-query", &["-s", package]);
61+
match self.run(&cmd) {
62+
Ok(_) => Ok(true),
63+
Err(_) => Ok(false),
64+
}
6465
}
6566

6667
/// Replace a file with a symlink. If the target file already exists, it will be backed up.

0 commit comments

Comments
 (0)