From a25be3cb0688e03573d8a39380ee347a3ce55839 Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Mon, 26 Aug 2019 09:35:11 +0000 Subject: kiss: better package upgrades FossilOrigin-Name: 6366f71a0acef2656fe47e0b18b22c8ac468e3fbd5f841d6036a59526aba12a5 --- kiss | 42 ++++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 14 deletions(-) diff --git a/kiss b/kiss index d5d9b99..b0cf36f 100755 --- a/kiss +++ b/kiss @@ -767,8 +767,11 @@ pkg_install() { # If the package is already installed (and this is an upgrade) make a # backup of the manifest file. - [ -f "$KISS_ROOT/$pkg_db/$pkg_name/manifest" ] && - cp -f "$KISS_ROOT/$pkg_db/$pkg_name/manifest" "$cac_dir/m-$pkg_name" + if [ -f "$KISS_ROOT/$pkg_db/$pkg_name/manifest" ]; then + old_manifest=$(cat "$KISS_ROOT/$pkg_db/$pkg_name/manifest") + else + old_manifest= + fi # This is repeated multiple times. Better to make it a function. pkg_rsync() { @@ -784,20 +787,34 @@ pkg_install() { rsync -HKav --ignore-existing "$tar_dir/$pkg_name/etc" "$KISS_ROOT/" # Remove any leftover files if this is an upgrade. - [ -f "$cac_dir/m-$pkg_name" ] && { - awk 'NR==FNR{lines[$0];next}!($0 in lines)' \ - "$KISS_ROOT/$pkg_db/$pkg_name/manifest" "$cac_dir/m-$pkg_name" | + [ "$old_manifest" ] && { + printf '%s\n' "$old_manifest" | + grep -vFxf "$KISS_ROOT/$pkg_db/$pkg_name/manifest" - | while read -r file; do # Skip deleting some leftover files. - [ -f "$KISS_ROOT/$file" ] && [ ! -L "$KISS_ROOT/$file" ] && - case $file in - *bin/rm|*bin/busybox|*bin/rsync|/etc/*) ;; - *) rm -f "$KISS_ROOT/$file" ;; - esac + case $file in + /etc/*|*bin/rm|*bin/busybox|*bin/rsync) continue ;; + esac + + file=$KISS_ROOT/$file + + # Remove files. + if [ -f "$file" ] && [ ! -L "$file" ]; then + rm -f "$file" + + # Remove file symlinks. + elif [ -L "$file" ] && [ ! -d "$file" ]; then + unlink "$file" ||: + + # Skip directory symlinks. + elif [ -L "$file" ] && [ -d "$file" ]; then + : # Remove directories if empty. - [ -d "$KISS_ROOT/$file" ] && rmdir "$file" 2>/dev/null ||: + elif [ -d "$file" ]; then + rmdir "$file" 2>/dev/null ||: + fi done ||: } @@ -911,9 +928,6 @@ pkg_clean() { # Remove temporary directories. rm -rf -- "$mak_dir" "$pkg_dir" "$tar_dir" - - # Remove temporary files. - set +f; rm -f "$cac_dir/m-"* } args() { -- cgit v1.2.3