Skip to content

Commit

Permalink
Faster package count on Alpine Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Gobidev committed May 27, 2024
1 parent 2205490 commit 7a71abb
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<usize> {

// 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;
}
Expand Down

0 comments on commit 7a71abb

Please sign in to comment.