From 04ced018883e09cb712e4bf45aacecea38f87b0f Mon Sep 17 00:00:00 2001 From: "dylan.araps@gmail.com" Date: Thu, 6 Feb 2020 11:22:18 +0000 Subject: kiss: Add function to pop list itemS FossilOrigin-Name: fa152731f4ed750890a1e9e540473774b0549d7d03ecff0c76ca4f70e017eb02 --- kiss | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-) (limited to 'kiss') diff --git a/kiss b/kiss index edb9ecc..47a17e4 100755 --- a/kiss +++ b/kiss @@ -69,6 +69,15 @@ esc() { "$(printf %s "$2" | sed 's/[\/&]/\\&/g')" } +pop() { + # Remove an item from a "string list". This allows us + # to remove a 'sed' call and reuse this code throughout. + del=$1 + shift "$(($# ? 1 : 0))" + + for i; do [ "$i" = "$del" ] || printf %s " $i "; done +} + pkg_lint() { # Check that each mandatory file in the package entry exists. log "$1" "Checking repository files" @@ -495,11 +504,9 @@ pkg_build() { # If an explicit package is a dependency of another explicit # package, remove it from the explicit list as it needs to be # installed as a dependency. + # shellcheck disable=2086 for pkg; do - # There's no better way to remove a word from a string in - # POSIX 'sh' sadly. - contains "$deps" "$pkg" && - explicit=$(printf %s "$explicit" | sed "s/ $pkg / /g") + contains "$deps" "$pkg" && explicit=$(pop "$pkg" $explicit) done # See [1] at top of script. @@ -534,7 +541,7 @@ pkg_build() { # list. No better way than using 'sed' in POSIX 'sh'. # See [1] at top of script. # shellcheck disable=2046,2086 - set -- $(printf %s " $* " | sed "s/ $pkg / /") + set -- $(pop "$pkg" "$@") } } done @@ -706,22 +713,10 @@ pkg_conflicts() { p_name=$2 - # Generate a list of all installed package manifests. - set +f - set -f -- "$sys_db"/*/manifest - - # Filter the manifest list and remove the previously - # installed version of the package if it exists. - for pkg; do - i_name=${pkg%/*} - i_name=${i_name##*/} - - shift "$(($# ? 1 : 0))" - - [ "$p_name" = "$i_name" ] && continue - - set -- "$@" "$pkg" - done + # Generate a list of all installed package manifests + # and remove the current package from the list. + # shellcheck disable=2046,2086 + set -- $(set +f; pop "$sys_db/$p_name/manifest" "$sys_db"/*/manifest) [ -s "$cac_dir/$pid-m" ] || return 0 -- cgit v1.2.3