Check source-repository-* files for trailing newline

Because we read this in via a bash loop, without a trailing newline we
can hit one of the oldest bash gotcha tricks and end up skipping the
final line (or only line, if there's only one) when the description
files don't have trailing newlines.  Add a check.

Change-Id: I23e293b957cd4f008611656cf9166391b1b537a2
This commit is contained in:
Ian Wienand 2017-12-08 14:22:47 +11:00
parent 7470ee26e0
commit 55537519e5
1 changed files with 9 additions and 0 deletions

View File

@ -86,6 +86,15 @@ for i in $(find $ELEMENTS_DIR -type f \
exclusions=("$(parse_exclusions $i)")
# source-repository does a read < $file and can miss the last line
# (or only line, if there's only one) when not newline terminated.
if [[ $(basename "${i}") =~ "source-repository-" ]]; then
nl=$(tail -c 1 ${i})
if [[ "${nl}" != "" ]]; then
error "$i does not end with a newline"
fi
fi
# Check that files starting with a shebang are +x
firstline=$(head -n 1 "$i")
if [ "${firstline:0:2}" = "#!" ]; then