Skip to main content

refresh_explicit_cache

Function refresh_explicit_cache 

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

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

Inputs:

  • mode: Filter mode determining which packages to query (LeafOnly or AllExplicit).
  • cache: Optional mutable reference to a HashSet<String> to update with results.

Output:

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

Details:

  • Uses pacman -Qetq for LeafOnly mode (explicitly installed AND not required).
  • Uses pacman -Qeq for AllExplicit mode (all explicitly installed).
  • 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_explicit_cache, InstalledPackagesMode};
use std::collections::HashSet;

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