aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2020-10-25 21:43:52 +0000
committermerakor <cem@ckyln.com>2020-10-25 21:43:52 +0000
commite3145335fb336b83e32ba22a0ec259e0c1cbe61a (patch)
treefe1695d0263e0c0d24418f0588a6b073fc63b43e
parent90ffb98b53b977c74adf3153ff6caa0ad7bc12cf (diff)
downloadcpt-e3145335fb336b83e32ba22a0ec259e0c1cbe61a.tar.gz
pkg_owner(): add function to retrieve the owning package of a file
This function is almost identical to the function with the same name on kiss. However, instead of saving the owner on a global variable, the function prints the owning package to the standard output. The function can be called similar to grep. The usage is: pkg_owner GREP_FLAGS FILE_TO_CHECK MANIFEST_LOCATIONS... If no manifest is specified, the function will use every installed package on the system database. FossilOrigin-Name: 53cbeff7a92850efd172960f12848885961655c9c53e24a5f8cb8da7642ce541
-rw-r--r--src/cpt-lib13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/cpt-lib b/src/cpt-lib
index 12d2f2d..56f43de 100644
--- a/src/cpt-lib
+++ b/src/cpt-lib
@@ -393,6 +393,19 @@ sh256() {
while read -r hash _; do printf '%s %s\n' "$hash" "$1"; done
}
+pkg_owner() {
+ set +f
+
+ [ "$3" ] || set -- "$1" "$2" "$sys_db"/*/manifest
+
+ pkg_owner=$(grep "$@")
+ pkg_owner=${pkg_owner%/*}
+ pkg_owner=${pkg_owner##*/}
+
+ set -f -- "$pkg_owner"; unset pkg_owner
+ [ "$1" ] && printf '%s\n' "$1"
+}
+
pkg_isbuilt() (
# Check if a package is built or not.
read -r ver rel < "$(pkg_find "$1")/version"