updpkgsums: don't try to add nonexistent checksums

Message ID 20210521041641.3656943-1-eschwartz@archlinux.org
State Accepted
Headers show
Series updpkgsums: don't try to add nonexistent checksums | expand

Commit Message

Eli Schwartz May 21, 2021, 4:16 a.m. UTC
In the event there are no sources, there won't be sums either. awk won't
find any to remove and replace inline, so it tries to print "" at the
end of the file, and merely adds superfluous newlines.

Abort early instead, since updpkgsums cannot be expected to process such
a file.

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---
 src/updpkgsums.sh.in | 5 +++++
 1 file changed, 5 insertions(+)

Comments

Daniel M. Capella July 28, 2021, 12:23 a.m. UTC | #1
Pushed, thank you!

On 5/21/21 12:16 AM, Eli Schwartz via pacman-contrib wrote:
> In the event there are no sources, there won't be sums either. awk won't
> find any to remove and replace inline, so it tries to print "" at the
> end of the file, and merely adds superfluous newlines.
>
> Abort early instead, since updpkgsums cannot be expected to process such
> a file.
>
> Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
> ---
>   src/updpkgsums.sh.in | 5 +++++
>   1 file changed, 5 insertions(+)
>
> diff --git a/src/updpkgsums.sh.in b/src/updpkgsums.sh.in
> index 41965f5..e5dbd2b 100644
> --- a/src/updpkgsums.sh.in
> +++ b/src/updpkgsums.sh.in
> @@ -99,6 +99,11 @@ newbuildfile=$(mktemp "${TMPDIR:-/tmp}/updpkgsums.XXXXXX")
>   trap "rm -rf '$BUILDDIR' '$newbuildfile'" EXIT
>   sumtypes=$(IFS='|'; echo "${known_hash_algos[*]}")
>   newsums=$(makepkg -g -p "$buildfile" "${MAKEPKG_OPTS[@]}") || die 'Failed to generate new checksums'
> +
> +if [[ -z $newsums ]]; then
> +	die "$buildfile does not contain sources to update"
> +fi
> +
>   awk -v sumtypes="$sumtypes" -v newsums="$newsums" '
>   	$0 ~"^[[:blank:]]*(" sumtypes ")sums(_[^=]+)?=", $0 ~ "\\)[[:blank:]]*(#.*)?$" {
>   		if (!w) {

Patch

diff --git a/src/updpkgsums.sh.in b/src/updpkgsums.sh.in
index 41965f5..e5dbd2b 100644
--- a/src/updpkgsums.sh.in
+++ b/src/updpkgsums.sh.in
@@ -99,6 +99,11 @@  newbuildfile=$(mktemp "${TMPDIR:-/tmp}/updpkgsums.XXXXXX")
 trap "rm -rf '$BUILDDIR' '$newbuildfile'" EXIT
 sumtypes=$(IFS='|'; echo "${known_hash_algos[*]}")
 newsums=$(makepkg -g -p "$buildfile" "${MAKEPKG_OPTS[@]}") || die 'Failed to generate new checksums'
+
+if [[ -z $newsums ]]; then
+	die "$buildfile does not contain sources to update"
+fi
+
 awk -v sumtypes="$sumtypes" -v newsums="$newsums" '
 	$0 ~"^[[:blank:]]*(" sumtypes ")sums(_[^=]+)?=", $0 ~ "\\)[[:blank:]]*(#.*)?$" {
 		if (!w) {