From 7df5272d1450f664f4107b1cf94e370002b5b63c Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Mar 27 2021 23:45:51 +0000 Subject: [PATCH 1/2] Handle empty lines in sources file Empty lines are ignored. Based on the similar commit in rhpkg-simple. Signed-off-by: Ondrej Nosek --- diff --git a/README.md b/README.md index 92e2b50..1c05593 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # fedpkg-minimal Helper script for Fedora buildystem to fetch sources. Project is hosted on -[Fedora Hosted](https://fedorahosted.org/fedpkg-minimal/). +[Pagure](https://pagure.io/fedpkg-minimal). ## Authors diff --git a/bin/fedpkg-base b/bin/fedpkg-base index 87d90e8..4b13f49 100755 --- a/bin/fedpkg-base +++ b/bin/fedpkg-base @@ -30,15 +30,21 @@ if [[ -s sources ]]; then # 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. while read -r _ filename _ hash; do + if [ -z "$filename" ] || [ -z "$hash" ]; then + continue + fi # Remove parenthesis around tarball name - filename=${filename#(} - tarball=${filename%)} + filename=${filename#(} + tarball=${filename%)} curl -L -H Pragma: -o "./$tarball" -R -S --fail --retry 5 --max-time 15 "$baseurl/$pkgname/$tarball/$hashtype/$hash/$tarball" done < sources "${hashtype}sum" -c sources else # Ok, we're working with MD5. while read -r md5sum tarball; do + if [ -z "$md5sum" ] || [ -z "$tarball" ]; then + continue + fi curl -L -H Pragma: -o "./$tarball" -R -S --fail --retry 5 --max-time 15 "$baseurl/$pkgname/$tarball/$md5sum/$tarball" done < sources md5sum -c sources diff --git a/tests/test_md5_bsd_empty_line/expected b/tests/test_md5_bsd_empty_line/expected new file mode 100644 index 0000000..f8c48b5 --- /dev/null +++ b/tests/test_md5_bsd_empty_line/expected @@ -0,0 +1,2 @@ +curl -L -H Pragma: -o ./github-linguist-4.8.18.gem -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/test_md5_bsd_empty_line/github-linguist-4.8.18.gem/md5/192de5f33807d72e573c54f61892fc69/github-linguist-4.8.18.gem +md5sum -c sources diff --git a/tests/test_md5_bsd_empty_line/sources b/tests/test_md5_bsd_empty_line/sources new file mode 100644 index 0000000..1319603 --- /dev/null +++ b/tests/test_md5_bsd_empty_line/sources @@ -0,0 +1,2 @@ +MD5 (github-linguist-4.8.18.gem) = 192de5f33807d72e573c54f61892fc69 + diff --git a/tests/test_md5_old_empty_line/expected b/tests/test_md5_old_empty_line/expected new file mode 100644 index 0000000..7415997 --- /dev/null +++ b/tests/test_md5_old_empty_line/expected @@ -0,0 +1,2 @@ +curl -L -H Pragma: -o ./entr-3.6.tar.gz -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/test_md5_old_empty_line/entr-3.6.tar.gz/072eed7153296a8fae6ebdedefed9fd4/entr-3.6.tar.gz +md5sum -c sources diff --git a/tests/test_md5_old_empty_line/sources b/tests/test_md5_old_empty_line/sources new file mode 100644 index 0000000..472c9e4 --- /dev/null +++ b/tests/test_md5_old_empty_line/sources @@ -0,0 +1,2 @@ +072eed7153296a8fae6ebdedefed9fd4 entr-3.6.tar.gz + diff --git a/tests/test_sha512_bsd_empty_line/expected b/tests/test_sha512_bsd_empty_line/expected new file mode 100644 index 0000000..3ebb63a --- /dev/null +++ b/tests/test_sha512_bsd_empty_line/expected @@ -0,0 +1,2 @@ +curl -L -H Pragma: -o ./github-linguist-4.8.18.gem -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/test_sha512_bsd_empty_line/github-linguist-4.8.18.gem/sha512/d556ffe0062bc2c745c46e94929eab18c79fd221ffc1dd0c0ea5868428bd130d7b15eec618e9c3940b50c27559923911135770792864f3330a606132dc8819c0/github-linguist-4.8.18.gem +sha512sum -c sources diff --git a/tests/test_sha512_bsd_empty_line/sources b/tests/test_sha512_bsd_empty_line/sources new file mode 100644 index 0000000..4b9b5bd --- /dev/null +++ b/tests/test_sha512_bsd_empty_line/sources @@ -0,0 +1,2 @@ +SHA512 (github-linguist-4.8.18.gem) = d556ffe0062bc2c745c46e94929eab18c79fd221ffc1dd0c0ea5868428bd130d7b15eec618e9c3940b50c27559923911135770792864f3330a606132dc8819c0 + From 52a2c33a834ebf1d4f31e3dc3fdb43168a6e42ec Mon Sep 17 00:00:00 2001 From: Ondrej Nosek Date: Mar 28 2021 17:12:45 +0000 Subject: [PATCH 2/2] Accept files without trailing new-line If the last line of sources file was not correctly terminated, we never downloaded the corresponding tarball. This is different to what real fedpkg does, which accepts the file. When encountering unterminated line, `read` exits with non-zero code, but it does assign the variables. Thus, if the variables are set, we try to download the file even if read reports problem. Based on similar commit in rhpkg-simple. JIRA: RHELCMP-4687 Resolves: rhbz#1943593 Signed-off-by: Ondrej Nosek --- diff --git a/bin/fedpkg-base b/bin/fedpkg-base index 4b13f49..3fc0998 100755 --- a/bin/fedpkg-base +++ b/bin/fedpkg-base @@ -29,7 +29,7 @@ if [[ -s sources ]]; then # SHA512 (filename) = ABCDEF # 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. - while read -r _ filename _ hash; do + while read -r _ filename _ hash || [[ -n "$filename" && -n "$hash" ]]; do if [ -z "$filename" ] || [ -z "$hash" ]; then continue fi @@ -41,7 +41,7 @@ if [[ -s sources ]]; then "${hashtype}sum" -c sources else # Ok, we're working with MD5. - while read -r md5sum tarball; do + while read -r md5sum tarball || [[ -n "$md5sum" && -n "$tarball" ]]; do if [ -z "$md5sum" ] || [ -z "$tarball" ]; then continue fi diff --git a/tests/test_md5_bsd_missing_endline/expected b/tests/test_md5_bsd_missing_endline/expected new file mode 100644 index 0000000..72dc0a8 --- /dev/null +++ b/tests/test_md5_bsd_missing_endline/expected @@ -0,0 +1,2 @@ +curl -L -H Pragma: -o ./github-linguist-4.8.18.gem -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/test_md5_bsd_missing_endline/github-linguist-4.8.18.gem/md5/192de5f33807d72e573c54f61892fc69/github-linguist-4.8.18.gem +md5sum -c sources diff --git a/tests/test_md5_bsd_missing_endline/sources b/tests/test_md5_bsd_missing_endline/sources new file mode 100644 index 0000000..b58ddbb --- /dev/null +++ b/tests/test_md5_bsd_missing_endline/sources @@ -0,0 +1 @@ +MD5 (github-linguist-4.8.18.gem) = 192de5f33807d72e573c54f61892fc69 \ No newline at end of file diff --git a/tests/test_md5_old_missing_endline/expected b/tests/test_md5_old_missing_endline/expected new file mode 100644 index 0000000..552ea3c --- /dev/null +++ b/tests/test_md5_old_missing_endline/expected @@ -0,0 +1,2 @@ +curl -L -H Pragma: -o ./entr-3.6.tar.gz -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/test_md5_old_missing_endline/entr-3.6.tar.gz/072eed7153296a8fae6ebdedefed9fd4/entr-3.6.tar.gz +md5sum -c sources diff --git a/tests/test_md5_old_missing_endline/sources b/tests/test_md5_old_missing_endline/sources new file mode 100644 index 0000000..d51d060 --- /dev/null +++ b/tests/test_md5_old_missing_endline/sources @@ -0,0 +1 @@ +072eed7153296a8fae6ebdedefed9fd4 entr-3.6.tar.gz \ No newline at end of file diff --git a/tests/test_sha512_bsd_missing_endline/expected b/tests/test_sha512_bsd_missing_endline/expected new file mode 100644 index 0000000..8521dfc --- /dev/null +++ b/tests/test_sha512_bsd_missing_endline/expected @@ -0,0 +1,2 @@ +curl -L -H Pragma: -o ./github-linguist-4.8.18.gem -R -S --fail --retry 5 --max-time 15 https://src.fedoraproject.org/repo/pkgs/test_sha512_bsd_missing_endline/github-linguist-4.8.18.gem/sha512/d556ffe0062bc2c745c46e94929eab18c79fd221ffc1dd0c0ea5868428bd130d7b15eec618e9c3940b50c27559923911135770792864f3330a606132dc8819c0/github-linguist-4.8.18.gem +sha512sum -c sources diff --git a/tests/test_sha512_bsd_missing_endline/sources b/tests/test_sha512_bsd_missing_endline/sources new file mode 100644 index 0000000..f565095 --- /dev/null +++ b/tests/test_sha512_bsd_missing_endline/sources @@ -0,0 +1 @@ +SHA512 (github-linguist-4.8.18.gem) = d556ffe0062bc2c745c46e94929eab18c79fd221ffc1dd0c0ea5868428bd130d7b15eec618e9c3940b50c27559923911135770792864f3330a606132dc8819c0 \ No newline at end of file