summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLyndon Brown <jnqnfe@gmail.com>2020-03-12 20:12:47 +0000
committerLyndon Brown <jnqnfe@gmail.com>2020-03-17 22:57:04 +0000
commit1b09b1527744a50baf4e0cd45aacced461e2d862 (patch)
tree230a655e214e5267780e1a9dea788dfea91be04a
parentdadeec9d396382d42bae0cf490dc55456fa71199 (diff)
downloadvyos-live-build-1b09b1527744a50baf4e0cd45aacced461e2d862.tar.gz
vyos-live-build-1b09b1527744a50baf4e0cd45aacced461e2d862.zip
stagefiles: refactor Require_stagefile()
- count of params is available as $#, we don't need the pipe-to-wc logic. - the whole 'CONTINUE' based logic is silly, we can just return once one of the files is found. - setting of 'NAME' in the loop was completely pointless. - the error message for multiple files was not very clear just injecting a sequence of words into a sentence. - it did not work correctly if no arguments were given (bad usage) note, you might question whether the functionality of this function is correct, as did I; this is tackled in a followup commit whilst this commit retains the existing functionality! Gbp-Dch: Short
-rwxr-xr-xfunctions/stagefile.sh41
1 files changed, 16 insertions, 25 deletions
diff --git a/functions/stagefile.sh b/functions/stagefile.sh
index 6f9e8cc8b..383df2c45 100755
--- a/functions/stagefile.sh
+++ b/functions/stagefile.sh
@@ -63,37 +63,28 @@ Remove_stagefile ()
rm -f "${FILE}"
}
+# Find at least one of the required stages, `exit 1` if none found
Require_stagefile ()
{
- local NAME
- local FILES
- local NUMBER
- NAME="$(basename ${0})"
- FILES="${@}" #must be on separate line to 'local' declaration to avoid error
- NUMBER="$(echo ${@} | wc -w)"
-
+ if [ $# -eq 0 ]; then
+ Echo_warning "Bad `Require_stagefile` usage, no params were supplied"
+ return 0
+ fi
local FILE
- local CONTINUE=false
- for FILE in ${FILES}
- do
- FILE=".build/${FILE}"
- # Find at least one of the required stages
- if [ -f ${FILE} ]
- then
- CONTINUE=true
- NAME="${NAME} $(basename ${FILE})"
+ for FILE in ${@}; do
+ if [ -f ".build/${FILE}" ]; then
+ return 0
fi
done
- if ! $CONTINUE
- then
- if [ "${NUMBER}" -eq 1 ]
- then
- Echo_error "%s: %s missing" "${NAME}" "${FILE}"
- else
- Echo_error "%s: one of %s is missing" "${NAME}" "${FILES}"
- fi
+ local NAME
+ NAME="$(basename ${0})"
- exit 1
+ if [ $# -eq 1 ]; then
+ Echo_error "%s requires stage: %s" "${NAME}" "${FILE}"
+ else
+ Echo_error "%s requires one of these stages: %s" "${NAME}" "$(echo ${@})"
fi
+
+ exit 1
}