Skip to main content

refresh_installed_cache

Function refresh_installed_cache 

Source
pub fn refresh_installed_cache(
    cache: Option<&mut HashSet<String>>,
) -> Result<HashSet<String>>
Expand description

What: Query pacman for all installed packages and optionally update a cache.

Inputs:

  • cache: Optional mutable reference to a HashSet<String> to update with results.

Output:

  • Returns Ok(HashSet<String>) containing all installed package names.
  • Returns Ok(HashSet::new()) on failure (graceful degradation).

Details:

  • Uses pacman -Qq to query the local database.
  • If cache is provided, updates it with the results.
  • Sets LC_ALL=C and LANG=C for consistent locale-independent output.
  • Logs errors for diagnostics but returns empty set to avoid blocking operations.

§Errors

This function does not return errors - it gracefully degrades by returning an empty set. Errors are logged using tracing::error for diagnostics.

§Example

use arch_toolkit::index::refresh_installed_cache;
use std::collections::HashSet;

let mut cache = HashSet::new();
let packages = refresh_installed_cache(Some(&mut cache)).unwrap();
println!("Found {} installed packages", packages.len());