diff --git a/contrib/kiss-preferred b/contrib/kiss-preferred deleted file mode 100755 index 7e8df27..0000000 --- a/contrib/kiss-preferred +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/sh -e -# Lists the owners of all files with conflicts - -kiss a | while read -r _ path; do - if owner=$(kiss owns "$path" 2>/dev/null) && [ "$owner" ]; then - printf '%s %s\n' "$owner" "$path" - - else - printf 'warning: %s has no owner\n' "$path" >&2 - fi -done - diff --git a/kiss b/kiss index a17f0d6..10395db 100755 --- a/kiss +++ b/kiss @@ -1319,6 +1319,33 @@ pkg_alternatives() { fi } +pkg_preferred() { + set +f + + ok "$1" || set -- "$sys_db/"* + + # shellcheck disable=2046 + set -- $( + for pkg; do + pkg="${pkg##*/}" + printf '%s\n' "$pkg/manifest" + done + ) + + cd "$sys_db" + + for manifest; do + [ -f "$manifest" ] || die "'${manifest%%/*}' not found" + done + + pkg_alternatives | + cut -d' ' -f2- | + grep -Fxf - "$@" /dev/null | + sed 's/\/manifest:/ /' + + cd "$OLDPWD" +} + pkg_swap() { # Swap between package alternatives. [ -d "$sys_db/$1" ] || die "'$1' not found" @@ -1515,7 +1542,21 @@ pkg_removable() { ! grep -lFx -- "$1" */depends || die "$1" "Not removable, has dependents" + preferred="$(pkg_preferred "$1")" + cnt=0 + + IFS=$newline + + for line in $preferred; do + printf '%s\n' "$line" + : $((cnt+=1)) + done + + [ ! "$cnt" -gt 0 ] || + die "$1" "Not removable, package leaves behind $cnt orphaned alternative(s)" + set -f + cd "$OLDPWD" } @@ -1911,7 +1952,7 @@ args() { esac ;; - b|build|c|checksum|d|download|i|install|l|list|r|remove) + b|build|c|checksum|d|download|i|install|l|list|p|preferred|r|remove) for _arg do case ${action%%"${action#?}"}-$_arg in i-*\!*|i-*\**|i-*\[*|i-*\ *|i-*\]*|i-*"$newline"*) die "Invalid argument: '!*[ ]\\n' ('$_arg')" @@ -1991,6 +2032,7 @@ args() { H|help-ext) pkg_help_ext "$@" ;; i|install) for pkg do pkg_install "$pkg"; done ;; l|list) pkg_list_version "$@" ;; + p|preferred) pkg_preferred "$@" ;; r|remove) for pkg in $redro; do pkg_remove "$pkg"; done ;; s|search) for pkg do pkg_find "$pkg" all; done ;; u|update) pkg_update ;;