From 3237598dc3c61e14ceec2819651fde8fed0e98cb Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Fri, 6 Nov 2020 08:49:56 +0200 Subject: [PATCH] kiss-owns: Allow all path types as input --- contrib/kiss-owns | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/contrib/kiss-owns b/contrib/kiss-owns index cde5550..44ea546 100755 --- a/contrib/kiss-owns +++ b/contrib/kiss-owns @@ -1,19 +1,31 @@ #!/bin/sh -e # Check which package owns a file -# Strip 'KISS_ROOT' from the file path if passed and -# follow symlinks. -file=$(readlink -f "$KISS_ROOT/${1##$KISS_ROOT}") +# Follow symlinks to any paths. +case $1 in + /*) + cd -P "$KISS_ROOT/${1%/*}" + ;; -[ -f "$file" ] || { + */*) + cd -P "${1%/*}" + ;; + + *) + cd -P . + ;; +esac + +[ -f "$PWD/${1##*/}" ] || { printf 'usage: kiss-owns [/path/to/file]\n' >&2 exit 1 } # Print the full path to the manifest file which contains # the match to our search. -pkg_owns=$(grep -lFx "${file##$KISS_ROOT}" \ - "$KISS_ROOT/var/db/kiss/installed/"*/manifest) +pkg_owns=$(grep -lFx \ + "$PWD/${1##*/}" \ + "$KISS_ROOT/var/db/kiss/installed/"*/manifest) # Extract the package name from the path above.