/****************************************************************************** __ ____ __ / / ___ ____ _/ __/_____________ _/ /__ / / / _ \/ __ `/ /_/ ___/ ___/ __ `/ / _ \ / /___/ __/ /_/ / __(__ ) /__/ /_/ / / __/ /_____/\___/\__,_/_/ /____/\___/\__,_/_/\___/ (C)opyright 2025, Leafscale, LLC - https://www.leafscale.com Project: Zygaena Filename: owner.reef Authors: Chris Tusa License: Description: Owner command - find which package owns a file ******************************************************************************/ module commands.owner import sys.args import core.str import core.config import core.database import core.pkgdb import types import util.color import exitcodes as ec export fn execute(opts: types.GlobalOptions): int end export fn execute(opts: types.GlobalOptions): int let argc = args.count() // File path should be at cmd_index + 1 if argc <= opts.cmd_index + 1 print_usage() return ec.EXIT_USAGE() end if // Load configuration and apply command-line overrides let base_cfg = config.load() let cfg = config.apply_overrides(base_cfg, opts.root, opts.prefix) let root_path = config.get_root(cfg) // Show root if set (verbose mode) if opts.verbose and str.length(root_path) > 0 color.print_info("Using root: " + root_path) end if let file_path = args.get(opts.cmd_index + 1) // Find owner (use rooted version if root is set) let owner = find_owner(file_path, root_path) if str.length(owner) == 0 color.print_error("No package owns: " + file_path) return ec.EXIT_PKG_NOT_FOUND() end if // Get package info (use rooted version if root is set) let pkg = get_installed_pkg(owner, root_path) color.print_action("File: " + file_path) println("") println("Owned by: " + owner + " " + pkg.info.version) return ec.EXIT_SUCCESS() end execute // Helper functions for rooted operations // Uses pkgdb for fast indexed lookup with fallback to database scan fn find_owner(file_path: string, root_path: string): string return pkgdb.find_file_owner_rooted(file_path, root_path) end find_owner fn get_installed_pkg(name: string, root_path: string): types.InstalledPackage if str.length(root_path) > 0 return database.get_installed_rooted(name, root_path) end if return database.get_installed(name) end get_installed_pkg proc print_usage() println("Usage: coral owner ") println("") println("Find which package owns a given file.") println("") println("Arguments:") println(" Path to the file to look up") println("") println("Examples:") println(" coral owner /usr/bin/vim") println(" coral owner /usr/bin/hello") end print_usage end module