kiss: Add function to pop list itemS

This commit is contained in:
Dylan Araps 2020-02-06 13:22:19 +02:00
parent bf78f79496
commit 6bb6cf6752
No known key found for this signature in database
GPG Key ID: 46D62DD9F1DE636E
1 changed files with 16 additions and 21 deletions

37
kiss
View File

@ -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