From 993f4ee9b107ba3ea1c2c6153aebfc5f37a9feb9 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sun, 26 Sep 2021 15:00:38 +0300 Subject: [PATCH] kiss-orphans: Performance improvements. Closes #275 --- contrib/kiss-orphans | 43 ++++++++++++++++++++++++++++++++++--------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/contrib/kiss-orphans b/contrib/kiss-orphans index 3456d74..9e8f2ee 100755 --- a/contrib/kiss-orphans +++ b/contrib/kiss-orphans @@ -1,16 +1,41 @@ #!/bin/sh -e # List orphaned packages -cd "$KISS_ROOT/var/db/kiss/installed/" +n=' +' -for pkg in *; do - case $pkg in - # Exemptions for orphans which aren't really - # orphans. Exclude them from the list. - baseinit|baselayout|gcc|e2fsprogs|musl|\ - make|busybox|bzip2|grub|kiss|git) - continue +cd "$KISS_ROOT/var/db/kiss/installed" +set -- * + +l=$n$( + for pkg do shift + set -- "$@" -e "$pkg" + done + + # Get a list of non-orphans. + grep -Fx "$@" -- */depends | + + { + # Strip filename. + sed s,.\*/depends:,, + + # Exclude packages which are not really orphans. + printf '%s\n' baseinit baselayout busybox bzip2 e2fsprogs gcc \ + git grub kiss make musl + } | + + # Remove duplicates. + sort -u +)$n + +# Generate the list of orphans by finding the inverse of the non-orphan list. +for pkg do shift + case $l in (*"$n$pkg$n"*) + continue esac - grep -q "^$pkg$" ./*/depends || printf '%s\n' "$pkg" + set -- "$@" "$pkg" done + +printf '%s\n' "$@" +