Macchina-CLI / libmacchina

A library providing access to all sorts of system information.
https://crates.io/crates/libmacchina
MIT License
68 stars 20 forks source link

Faster package count on Alpine Linux #170

Closed Gobidev closed 5 months ago

Gobidev commented 6 months ago

On Alpine Linux, packages can be counted by counting the amount of empty lines in /lib/apk/db/installed. On my test VM, this takes about 5ms compared to 80ms with the previous method with 82 packages installed.

I left the previous counting method as fallback, in case there are systems that use apk where the new one does not work.

Related to https://github.com/Gobidev/pfetch-rs/issues/48

grtcdr commented 5 months ago

How does the installed file look like? I presume that this method works and it's so odd that it does.

Gobidev commented 5 months ago

The file contains information about the installed packages, where the individual packages are separated by blank lines.

This is an example from one of my testing VMs: installed

I have tested this method with various amounts of packages installed and so far it was accurate without the need to correct for off-by-one errors.

grtcdr commented 5 months ago

Great, thanks for the attachment! Let's merge it.