summaryrefslogtreecommitdiffstats
path: root/lib/metadata
diff options
context:
space:
mode:
authorPatrick McDermott <patrick.mcdermott@libiquity.com>2019-03-13 02:51:56 (EDT)
committer Patrick McDermott <patrick.mcdermott@libiquity.com>2019-03-13 02:56:19 (EDT)
commit9033d4b6b9b85ab3e502b376daf66ae566c026b6 (patch)
tree5933fa9a313caff0ec5a0aa38e4087cba777c6d8 /lib/metadata
parente153a4a392e2f6e616b2c94b77eb683eff9e644a (diff)
libopkbuild: Abort on invalid function arguments
Shift arguments and abort instead of returning 125. Incorrect numbers of function arguments suggest application/library incompatibilities or serious errors by the application developer. Either way, the application developer should be made immediately aware of this (and not allowed to simply not check return values), and continuing to run and handle any further API calls may be unsafe.
Diffstat (limited to 'lib/metadata')
-rw-r--r--lib/metadata/proteanos.sh65
1 files changed, 23 insertions, 42 deletions
diff --git a/lib/metadata/proteanos.sh b/lib/metadata/proteanos.sh
index 514f8cb..4152847 100644
--- a/lib/metadata/proteanos.sh
+++ b/lib/metadata/proteanos.sh
@@ -27,9 +27,8 @@ _OB_VERSION_RE_PROTEANOS=${_OB_VERSION_RE_PROTEANOS}'$'
_ob_validate_source_name()
{
- local name=
-
- name="${1}"
+ local name="${1}"
+ shift 1 || _ob_abort
if grep -E "${_OB_NAME_RE_PROTEANOS}" >/dev/null 2>&1 <<-EOF
${name}
@@ -49,9 +48,8 @@ _ob_validate_source_name()
_ob_validate_binary_name()
{
- local name=
-
- name="${1}"
+ local name="${1}"
+ shift 1 || _ob_abort
if grep -E "${_OB_NAME_RE_PROTEANOS}" >/dev/null 2>&1 <<-EOF
${name}
@@ -71,9 +69,8 @@ _ob_validate_binary_name()
_ob_validate_version()
{
- local version=
-
- version="${1}"
+ local version="${1}"
+ shift 1 || _ob_abort
grep -E "${_OB_VERSION_RE_PROTEANOS}" >/dev/null 2>&1 <<-EOF
${version}
@@ -84,9 +81,8 @@ _ob_validate_version()
_ob_get_upstreamver()
{
- local version=
-
- version="${1}"
+ local version="${1}"
+ shift 1 || _ob_abort
printf '%s' "${version%-*}"
@@ -95,9 +91,8 @@ _ob_get_upstreamver()
_ob_get_distrev()
{
- local version=
-
- version="${1}"
+ local version="${1}"
+ shift 1 || _ob_abort
printf '%s' "${version##*-}"
@@ -120,47 +115,33 @@ _ob_get_system_plat()
_ob_get_system_path()
{
- local path_id=
+ local path_id="${1}"
+ shift 1 || _ob_abort
local pkgver=
- path_id="${1}"
- shift 1
-
case "${path_id}" in
'package-source')
# source version
- if [ ${#} -eq 2 ]; then
- printf '/usr/src/%s_%s' "${1}" "${2}"
- else
- return 125
- fi
+ [ ${#} -eq 2 ] || _ob_abort
+ printf '/usr/src/%s_%s' "${1}" "${2}"
;;
'package-docs')
# source version
- if [ ${#} -eq 2 ]; then
- printf '/usr/share/doc/%s' "${1}"
- else
- return 125
- fi
+ [ ${#} -eq 2 ] || _ob_abort
+ printf '/usr/share/doc/%s' "${1}"
;;
'buildflags')
# arch
- if [ ${#} -eq 1 ]; then
- printf "${DATADIR}/opkbuild/buildflags/%s" "${1}"
- else
- return 125
- fi
+ [ ${#} -eq 1 ] || _ob_abort
+ printf "${DATADIR}/opkbuild/buildflags/%s" "${1}"
;;
'platconf')
# source version plat
- if [ ${#} -eq 3 ]; then
- ob_parse_version -u 'pkgver' "${2}"
- printf "${DATADIR}/platconf/%s/%s\n" "${3}" "${1}"
- printf "${DATADIR}/platconf/%s/%s_%s\n" "${3}" "${1}" \
- "${pkgver}"
- else
- return 125
- fi
+ [ ${#} -eq 3 ] || _ob_abort
+ ob_parse_version -u 'pkgver' "${2}"
+ printf "${DATADIR}/platconf/%s/%s\n" "${3}" "${1}"
+ printf "${DATADIR}/platconf/%s/%s_%s\n" "${3}" "${1}" \
+ "${pkgver}"
;;
esac