Skip to main content

zoi_cli/cmd/
owner.rs

1use crate::pkg::local;
2use anyhow::Result;
3use colored::*;
4use std::path::Path;
5
6pub fn run(path: &Path) -> Result<()> {
7    let absolute_path = match path.canonicalize() {
8        Ok(p) => p,
9        Err(_) => path.to_path_buf(),
10    };
11
12    println!("Querying for file: {}", absolute_path.display());
13
14    let installed_packages = local::get_installed_packages()?;
15
16    for pkg in installed_packages {
17        if pkg
18            .installed_files
19            .iter()
20            .any(|f| Path::new(f) == absolute_path)
21        {
22            println!(
23                "{} is owned by {} {}",
24                absolute_path.display(),
25                pkg.name.cyan(),
26                pkg.version.yellow()
27            );
28            return Ok(());
29        }
30    }
31
32    println!("No package owns file: {}", absolute_path.display());
33    Ok(())
34}