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 viapacman -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=CandLANG=Cfor consistent locale-independent output.
§Errors
- Returns
PackageNotFoundwhen the package is not installed. - Returns
Parsewhen 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);