Version file read improvements (#2269)
* Don't bother reading empty version files * Implement version file read in pure bash Is faster with usual sized version files, slower with degenerate cases.
This commit is contained in:
parent
867f34b596
commit
c3fd96c429
@ -5,18 +5,17 @@ set -e
|
|||||||
|
|
||||||
VERSION_FILE="$1"
|
VERSION_FILE="$1"
|
||||||
|
|
||||||
if [ -e "$VERSION_FILE" ]; then
|
if [ -s "$VERSION_FILE" ]; then
|
||||||
# Read the first non-whitespace word from the specified version file.
|
# Read the first non-whitespace word from the specified version file.
|
||||||
# Be careful not to load it whole in case there's something crazy in it.
|
# Be careful not to load it whole in case there's something crazy in it.
|
||||||
IFS="${IFS}"$'\r'
|
IFS="${IFS}"$'\r'
|
||||||
words=($(cut -b 1-1024 "$VERSION_FILE" | sed -n 's/^[[:space:]]*\([^[:space:]#][^[:space:]]*\).*/\1/p'))
|
sep=
|
||||||
versions=("${words[@]}")
|
while read -n 1024 -r version _ || [[ $version ]]; do
|
||||||
|
[[ -z $version || $version == \#* ]] && continue
|
||||||
if [ -n "$versions" ]; then
|
printf "%s%s" "$sep" "$version"
|
||||||
IFS=":"
|
sep=:
|
||||||
echo "${versions[*]}"
|
done <"$VERSION_FILE"
|
||||||
exit
|
[[ $sep ]] && { echo; exit; }
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exit 1
|
exit 1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user