Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Faster package count on Alpine Linux #170

Merged
merged 1 commit into from
Jun 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/linux/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -855,6 +855,12 @@ 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