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