diff --git a/src/linux/mod.rs b/src/linux/mod.rs index 5bc39a4..3f08eb5 100644 --- a/src/linux/mod.rs +++ b/src/linux/mod.rs @@ -9,6 +9,7 @@ use crate::extra::path_extension; use crate::shared; use crate::traits::*; use itertools::Itertools; +use nix::NixPath; use pciid_parser::Database; use regex::Regex; use std::fs; @@ -855,6 +856,13 @@ impl LinuxPackageReadout { /// Returns the number of installed packages for systems /// that utilize `apk` as their package manager. fn count_apk() -> Option { + + // faster method for alpine: count empty lines in /lib/apk/db/installed + if let Ok(content) = fs::read_to_string(Path::new("/lib/apk/db/installed")) { + return Some(content.lines().filter(|l| l.is_empty()).count()); + } + + // fallback to command invocation if !extra::which("apk") { return None; }