kiss: bail out if package removal would break alternatives (#89)

Co-authored-by: git-bruh <e817509a-8ee9-4332-b0ad-3a6bdf9ab63f@aleeas.com>
Reviewed-on: https://codeberg.org/kiss-community/kiss/pulls/89
This commit is contained in:
Pratham 2022-10-07 17:13:02 +02:00
parent cb9fe25776
commit 2f4fc41582
2 changed files with 43 additions and 13 deletions

View File

@ -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

44
kiss
View File

@ -1319,6 +1319,33 @@ pkg_alternatives() {
fi 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() { pkg_swap() {
# Swap between package alternatives. # Swap between package alternatives.
[ -d "$sys_db/$1" ] || die "'$1' not found" [ -d "$sys_db/$1" ] || die "'$1' not found"
@ -1515,7 +1542,21 @@ pkg_removable() {
! grep -lFx -- "$1" */depends || ! grep -lFx -- "$1" */depends ||
die "$1" "Not removable, has dependents" 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 set -f
cd "$OLDPWD" cd "$OLDPWD"
} }
@ -1911,7 +1952,7 @@ args() {
esac 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 for _arg do case ${action%%"${action#?}"}-$_arg in
i-*\!*|i-*\**|i-*\[*|i-*\ *|i-*\]*|i-*"$newline"*) i-*\!*|i-*\**|i-*\[*|i-*\ *|i-*\]*|i-*"$newline"*)
die "Invalid argument: '!*[ ]\\n' ('$_arg')" die "Invalid argument: '!*[ ]\\n' ('$_arg')"
@ -1991,6 +2032,7 @@ args() {
H|help-ext) pkg_help_ext "$@" ;; H|help-ext) pkg_help_ext "$@" ;;
i|install) for pkg do pkg_install "$pkg"; done ;; i|install) for pkg do pkg_install "$pkg"; done ;;
l|list) pkg_list_version "$@" ;; l|list) pkg_list_version "$@" ;;
p|preferred) pkg_preferred "$@" ;;
r|remove) for pkg in $redro; do pkg_remove "$pkg"; done ;; r|remove) for pkg in $redro; do pkg_remove "$pkg"; done ;;
s|search) for pkg do pkg_find "$pkg" all; done ;; s|search) for pkg do pkg_find "$pkg" all; done ;;
u|update) pkg_update ;; u|update) pkg_update ;;