diff options
author | dylan.araps@gmail.com <dylan.araps@gmail.com> | 2019-07-04 14:25:28 +0000 |
---|---|---|
committer | dylan.araps@gmail.com <dylan.araps@gmail.com> | 2019-07-04 14:25:28 +0000 |
commit | a5aa2aa71398d24b6c41461d9b67d7b3ecca2d82 (patch) | |
tree | 3194f8d01d126219ac810c478609ef0dcb28cc53 | |
parent | c12d2d2b8d1e68d748c880a50061682a995d2c66 (diff) | |
download | cpt-a5aa2aa71398d24b6c41461d9b67d7b3ecca2d82.tar.gz |
kiss: Added dependency check on package removal.
FossilOrigin-Name: 87a69f746c597535224d79a36f07349ac0edcfe4f3f39f117d0f67b22c647165
-rwxr-xr-x | kiss | 51 |
1 files changed, 31 insertions, 20 deletions
@@ -565,28 +565,38 @@ pkg_remove() { cp "$(command -v rm)" "$cac_dir" cp "$(command -v rmdir)" "$cac_dir" - for pkg; do - # The package is not installed, don't do anything. - pkg_list "$pkg" >/dev/null || { - log "[$pkg]: Not installed." - continue - } + # The package is not installed, don't do anything. + pkg_list "$1" >/dev/null || { + log "[$1]: Not installed." + return + } + + # Make sure that nothing depends on this package. + [ "$2" = check ] && for file in "$KISS_ROOT/var/db/kiss/"*; do + # Check each depends file for the package and if it's + # a run-time dependency, append to the $required_by string. + grep -q "^$1$" "$file/depends" 2>/dev/null && + required_by="$required_by${file##*/}, " + done - while read -r file; do - # The file is in '/etc' skip it. This prevents the package - # manager from removing user edited configuration files. - [ "${file##/etc/*}" ] || continue + [ "$required_by" ] && + die "[$1]: Package is required by ${required_by%, }." \ + "[$1]: Aborting here..." - if [ -d "$KISS_ROOT/$file" ]; then - "$cac_dir/rmdir" "$KISS_ROOT/$file" 2>/dev/null || continue - else - "$cac_dir/rm" -f -- "$KISS_ROOT/$file" || - log "[$pkg]: Failed to remove '$file'." - fi - done < "$KISS_ROOT/var/db/kiss/$pkg/manifest" + while read -r file; do + # The file is in '/etc' skip it. This prevents the package + # manager from removing user edited configuration files. + [ "${file##/etc/*}" ] || continue - log "[$pkg]: Removed successfully." - done + if [ -d "$KISS_ROOT/$file" ]; then + "$cac_dir/rmdir" "$KISS_ROOT/$file" 2>/dev/null || continue + else + "$cac_dir/rm" -f -- "$KISS_ROOT/$file" || + log "[$1]: Failed to remove '$file'." + fi + done < "$KISS_ROOT/var/db/kiss/$1/manifest" + + log "[$1]: Removed successfully." } pkg_install() { @@ -643,6 +653,7 @@ pkg_install() { log "[$pkg_name]: Removing previous version of package if it exists." pkg_remove "$pkg_name" + log "[$pkg_name]: Installing package..." # Installation works by unpacking the tar-ball to a specified location, # manually running 'mkdir' to create each directory and finally, using @@ -814,7 +825,7 @@ args() { shift [ "$1" ] || die "'kiss remove' requires an argument." root_check - pkg_remove "$@" + for pkg; do pkg_remove "$pkg" check; done ;; # List installed packages. |