aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormerakor <cem@ckyln.com>2021-02-23 13:37:02 +0000
committermerakor <cem@ckyln.com>2021-02-23 13:37:02 +0000
commitf134f150ed336ad6b418806ce5720c07507b3913 (patch)
treedadad5abc645c9b4bd69f42cca53ad65d751b203 /src
parentae36bb5fa6bc346bf7c39b73648ac689bf2cfdb4 (diff)
downloadcpt-f134f150ed336ad6b418806ce5720c07507b3913.tar.gz
pkg_{gentree,get_base}(): use format for newline handling
FossilOrigin-Name: 422290edbd1d0c1cf98ae3d239f49c901eadf736f957bf1328df939de2cc9f63
Diffstat (limited to 'src')
-rw-r--r--src/cpt-lib.in21
1 files changed, 16 insertions, 5 deletions
diff --git a/src/cpt-lib.in b/src/cpt-lib.in
index a978ebd..2c7471f 100644
--- a/src/cpt-lib.in
+++ b/src/cpt-lib.in
@@ -1860,7 +1860,11 @@ pkg_get_base() (
# cpt-base is an optional file, return with success if it doesn't exist.
[ -f "$CPT_ROOT/etc/cpt-base" ] || return 0
- nonl=$1; set --
+
+ # If there is an argument, change the format to use spaces instead of
+ # newlines.
+ format='%s\n'
+ [ "$#" -eq 0 ] || format='%s '; set --
# Older versions of shellcheck warns us that the variable is changing on the
# subshell. That is our purpose here, thank you very much.
@@ -1873,7 +1877,10 @@ pkg_get_base() (
contains "$*" "$dep" || set -- "$@" "$dep"
done
done < "$CPT_ROOT/etc/cpt-base"
- if [ "$nonl" ]; then printf '%s ' "$@"; else printf '%s\n' "$@"; fi
+
+ # Format variable is intentional.
+ # shellcheck disable=2059
+ printf "$format" "$@"
)
pkg_gentree() (
@@ -1882,14 +1889,14 @@ pkg_gentree() (
# given package. A second argument can be given as a combination of
# characters (similar to 'tar(1)' keys) which will be used as an option
# parser. See the documentation for more information on the keys.
- deps='' reverse='' nonl='' make_deps=first
+ deps='' reverse='' format='%s\n' make_deps=first
for op in $(sepchar "$2"); do
case "$op" in
b) deps="$(pkg_get_base nonl)" ;;
f) make_deps='' ;;
x) make_deps=first-nomake ;;
r) reverse=1 ;;
- n) nonl=1 ;;
+ n) format='%s ' ;;
*) die "pkg_gentree: Unknown key '$op'"
esac
done
@@ -1897,7 +1904,11 @@ pkg_gentree() (
eval set -- "$deps"
pkg_order "$@"
if [ "$reverse" ]; then eval set -- "$redro"; else eval set -- "$order"; fi
- if [ "$nonl" ]; then printf '%s ' "$@"; else printf '%s\n' "$@"; fi
+ [ "$1" ] || return 0
+
+ # Format variable is intentional.
+ # shellcheck disable=2059
+ printf "$format" "$@"
)
pkg_clean() {