Adjust get_sources.sh to allow empty sources file

There are situations in which one will want to use a `sources` file to
indicate that they wish to use the flat dist-git layout.
However, until now we did not allow empty `sources` file in flat dist-git
layout.
With this change we allow empty `sources` file and we will just echo
something in the logs saying that this file is empty and bail.

Signed-off-by: Pierre-Yves Chibon <pingou@pingoured.fr>
This commit is contained in:
Pierre-Yves Chibon 2022-03-03 09:53:43 +01:00
parent 014e3890be
commit 04de770669

94
get_sources.sh Executable file → Normal file
View file

@ -146,52 +146,56 @@ else
done <<< "$(git branch -r --contains HEAD | sed 's#origin/##g')" done <<< "$(git branch -r --contains HEAD | sed 's#origin/##g')"
fi fi
if [[ -s sources ]]; then if [[ -f sources ]]; then
# This section is for the "flat" dist-git layout, where the spec file and if [[ ! -s sources ]]; then
# patches are all present at the top level directory and the sha of the tarball echo "Empty sources file -- nothing to check"
# present in a 'sources' file. else
# This code was re-used from the fedpkg-pkg minimal project which is licensed # This section is for the "flat" dist-git layout, where the spec file and
# under GPLv3 or any later version. # patches are all present at the top level directory and the sha of the tarball
# present in a 'sources' file.
# This code was re-used from the fedpkg-pkg minimal project which is licensed
# under GPLv3 or any later version.
pkgname=$(basename "$PWD") pkgname=$(basename "$PWD")
# Read first word of first line. For old MD5 format it's the 32 character # Read first word of first line. For old MD5 format it's the 32 character
# hash. Otherwise let's assume the sources have the BSD format where lines # hash. Otherwise let's assume the sources have the BSD format where lines
# start with hash type. # start with hash type.
hashtype="$(head -n1 sources | cut -d' ' -f1 | tr '[:upper:]' '[:lower:]')" hashtype="$(head -n1 sources | cut -d' ' -f1 | tr '[:upper:]' '[:lower:]')"
# The format is # The format is
# SHA512 (filename) = ABCDEF # SHA512 (filename) = ABCDEF
# We don't care about the equals sign. We also assume all hashes are # We don't care about the equals sign. We also assume all hashes are
# the same type, so we don't need to read it again for each line. # the same type, so we don't need to read it again for each line.
while read -r _ filename _ hash || [[ -n "$filename" && -n "$hash" ]]; do while read -r _ filename _ hash || [[ -n "$filename" && -n "$hash" ]]; do
if [ -z "$filename" ] || [ -z "$hash" ]; then if [ -z "$filename" ] || [ -z "$hash" ]; then
continue continue
fi fi
# Remove parenthesis around tarball name # Remove parenthesis around tarball name
filename=${filename#(} filename=${filename#(}
tarball=${filename%)} tarball=${filename%)}
if [ ! -e "$tarball" ]; then if [ ! -e "$tarball" ]; then
for br in "${branches[@]}" for br in "${branches[@]}"
do do
br=$(echo ${br}| sed -e s'|remotes/origin/||') br=$(echo ${br}| sed -e s'|remotes/origin/||')
# Try the branch-specific lookaside structure # Try the branch-specific lookaside structure
url="${SURL}/$pkgname/${br}/$hash" url="${SURL}/$pkgname/${br}/$hash"
echo "Retrieving ${url}" echo "Retrieving ${url}"
HTTP_CODE=$(curl -L ${QUIET} -H Pragma: -o "./$tarball" -R -S --fail --retry 5 "${url}" --write-out "%{http_code}" || true) HTTP_CODE=$(curl -L ${QUIET} -H Pragma: -o "./$tarball" -R -S --fail --retry 5 "${url}" --write-out "%{http_code}" || true)
echo "Returned ${HTTP_CODE}" echo "Returned ${HTTP_CODE}"
if [[ ${HTTP_CODE} -gt 199 && ${HTTP_CODE} -lt 300 ]] ; then if [[ ${HTTP_CODE} -gt 199 && ${HTTP_CODE} -lt 300 ]] ; then
echo "bailing" echo "bailing"
break break
fi fi
# Try the hash-specific lookaside structure # Try the hash-specific lookaside structure
url="${SURL}/$pkgname/$tarball/$hashtype/$hash/$tarball" url="${SURL}/$pkgname/$tarball/$hashtype/$hash/$tarball"
echo "Retrieving ${url}" echo "Retrieving ${url}"
curl -L ${QUIET} -H Pragma: -o "./$tarball" -R -S --fail --retry 5 "${url}" && break curl -L ${QUIET} -H Pragma: -o "./$tarball" -R -S --fail --retry 5 "${url}" && break
done done
else else
echo "$filename exists. skipping" echo "$filename exists. skipping"
fi fi
done < sources done < sources
"${hashtype}sum" -c sources "${hashtype}sum" -c sources
fi
else else
# This section is for the "non-flat" dist-git layout, where the spec file # This section is for the "non-flat" dist-git layout, where the spec file
# is stored in a SPECS folder, the patches in a SOURCES folder and the sha # is stored in a SPECS folder, the patches in a SOURCES folder and the sha