get_installed_version

Function get_installed_version 

Source
pub fn get_installed_version(name: &str) -> Result<String>
Expand description

What: Retrieve the locally installed version of a package.

Inputs:

  • name: Package to query via pacman -Q.

Output:

  • Returns Ok(String) with the installed version string on success.
  • Returns Err(ArchToolkitError::PackageNotFound) if the package is not installed.
  • Returns Err(ArchToolkitError::Parse) if the version string cannot be parsed.

Details:

  • Normalizes versions by removing revision suffixes to facilitate requirement comparisons.
  • Parses format: “name version” or “name version-revision”.
  • Strips revision suffix (e.g., “1.2.3-1” -> “1.2.3”).
  • Sets LC_ALL=C and LANG=C for consistent locale-independent output.

§Errors

  • Returns PackageNotFound when the package is not installed.
  • Returns Parse when the version string cannot be parsed from command output.

§Example

use arch_toolkit::deps::get_installed_version;

let version = get_installed_version("pacman")?;
println!("Installed version: {}", version);