forked from kiss-community/kiss
kiss: refactor removal check
Moves the code into its own function and removes the subshell usage.
This commit is contained in:
parent
3c8057acfb
commit
048a79d471
27
kiss
27
kiss
@ -1140,18 +1140,29 @@ pkg_etc() (
|
|||||||
done ||:
|
done ||:
|
||||||
)
|
)
|
||||||
|
|
||||||
|
pkg_removable() {
|
||||||
|
# Check if a package is removable and die if it is not.
|
||||||
|
# A package is removable when it has no dependents or
|
||||||
|
# when KISS_FORCE is set to 1.
|
||||||
|
case ${KISS_FORCE:=0} in 0)
|
||||||
|
log "$1" "Checking if package removable"
|
||||||
|
|
||||||
|
cd "$sys_db"
|
||||||
|
set +f
|
||||||
|
|
||||||
|
! grep -lFx -- "$1" */depends ||
|
||||||
|
die "$1" "Not removable, has dependents"
|
||||||
|
|
||||||
|
set -f
|
||||||
|
cd "$OLDPWD"
|
||||||
|
esac
|
||||||
|
}
|
||||||
|
|
||||||
pkg_remove() {
|
pkg_remove() {
|
||||||
# Remove a package and all of its files. The '/etc' directory is handled
|
# Remove a package and all of its files. The '/etc' directory is handled
|
||||||
# differently and configuration files are *not* overwritten.
|
# differently and configuration files are *not* overwritten.
|
||||||
pkg_list "$1" >/dev/null || return
|
pkg_list "$1" >/dev/null || return
|
||||||
|
pkg_removable "$1"
|
||||||
# Make sure that nothing depends on this package.
|
|
||||||
[ "$KISS_FORCE" = 1 ] || {
|
|
||||||
log "$1" "Checking for reverse dependencies"
|
|
||||||
|
|
||||||
(cd "$sys_db"; set +f; grep -lFx "$1" -- */depends) &&
|
|
||||||
die "$1" "Can't remove package, others depend on it"
|
|
||||||
}
|
|
||||||
|
|
||||||
# Block being able to abort the script with 'Ctrl+C' during removal.
|
# Block being able to abort the script with 'Ctrl+C' during removal.
|
||||||
# Removes all risk of the user aborting a package removal leaving an
|
# Removes all risk of the user aborting a package removal leaving an
|
||||||
|
Loading…
Reference in New Issue
Block a user