[1/2] fff-hoods: let sha256sum read file directly

Submitted by Adrian Schmutzler on July 31, 2020, 11:28 p.m.

Details

Message ID 20200731232834.19763-1-freifunk@adrianschmutzler.de
State Accepted
Headers show

Commit Message

Adrian Schmutzler July 31, 2020, 11:28 p.m.
This removes two useless cat as found by shellcheck:

  sumnew=$(cat "$hoodfiletmp" 2>/dev/null | sha256sum | cut -f1 -d " ")
               ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead.

While not functionally relevant in our case, note that

  cat <non-existant-file> | sha256sum

actually returns a hash code, while

  sha256sum <non-existant-file>

does not return anything on stdout.

Since we check the existance of $hoodfiletmp before calling sha256sum,
though, we always have a hash value for at least one file, so two empty
checksum won't happen at that point.

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
---
 src/packages/fff/fff-hoods/Makefile                     | 2 +-
 src/packages/fff/fff-hoods/files/usr/sbin/configurehood | 4 ++--
 2 files changed, 3 insertions(+), 3 deletions(-)

Patch hide | download patch | download mbox

diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-hoods/Makefile
index d48e7b27..e166666a 100644
--- a/src/packages/fff/fff-hoods/Makefile
+++ b/src/packages/fff/fff-hoods/Makefile
@@ -1,7 +1,7 @@ 
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=fff-hoods
-PKG_RELEASE:=13
+PKG_RELEASE:=14
 
 PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
 
diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
index 1df6e2a5..99f0fce4 100755
--- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
+++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
@@ -78,8 +78,8 @@  if [ -s "$hoodfiletmp" ]; then
 	# https://pw.freifunk-franken.de/patch/205/
 	# but without signature, every hood file we get is valid!
 
-	sumnew=$(cat "$hoodfiletmp" 2>/dev/null | sha256sum | cut -f1 -d " ")
-	sumold=$(cat "$hoodfileref" 2>/dev/null | sha256sum | cut -f1 -d " ")
+	sumnew=$(sha256sum "$hoodfiletmp" 2>/dev/null | cut -f1 -d " ")
+	sumold=$(sha256sum "$hoodfileref" 2>/dev/null | cut -f1 -d " ")
 
 	json_load "$(cat "$hoodfiletmp")"
 

Comments

Fabian Blaese Aug. 1, 2020, 9:09 a.m.
Reviewed-by: Fabian Bläse <fabian@blaese.de>
Adrian Schmutzler Aug. 1, 2020, 10:11 a.m.
Beide applied.

> -----Original Message-----
> From: franken-dev [mailto:franken-dev-bounces@freifunk.net] On Behalf
> Of Adrian Schmutzler
> Sent: Samstag, 1. August 2020 01:29
> To: franken-dev@freifunk.net
> Subject: [PATCH 1/2] fff-hoods: let sha256sum read file directly
> 
> This removes two useless cat as found by shellcheck:
> 
>   sumnew=$(cat "$hoodfiletmp" 2>/dev/null | sha256sum | cut -f1 -d " ")
>                ^-- SC2002: Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..'
> instead.
> 
> While not functionally relevant in our case, note that
> 
>   cat <non-existant-file> | sha256sum
> 
> actually returns a hash code, while
> 
>   sha256sum <non-existant-file>
> 
> does not return anything on stdout.
> 
> Since we check the existance of $hoodfiletmp before calling sha256sum,
> though, we always have a hash value for at least one file, so two empty
> checksum won't happen at that point.
> 
> Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
> ---
>  src/packages/fff/fff-hoods/Makefile                     | 2 +-
>  src/packages/fff/fff-hoods/files/usr/sbin/configurehood | 4 ++--
>  2 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/src/packages/fff/fff-hoods/Makefile b/src/packages/fff/fff-
> hoods/Makefile
> index d48e7b27..e166666a 100644
> --- a/src/packages/fff/fff-hoods/Makefile
> +++ b/src/packages/fff/fff-hoods/Makefile
> @@ -1,7 +1,7 @@
>  include $(TOPDIR)/rules.mk
> 
>  PKG_NAME:=fff-hoods
> -PKG_RELEASE:=13
> +PKG_RELEASE:=14
> 
>  PKG_BUILD_DIR:=$(BUILD_DIR)/$(PKG_NAME)
> 
> diff --git a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> index 1df6e2a5..99f0fce4 100755
> --- a/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> +++ b/src/packages/fff/fff-hoods/files/usr/sbin/configurehood
> @@ -78,8 +78,8 @@ if [ -s "$hoodfiletmp" ]; then
>  	# https://pw.freifunk-franken.de/patch/205/
>  	# but without signature, every hood file we get is valid!
> 
> -	sumnew=$(cat "$hoodfiletmp" 2>/dev/null | sha256sum | cut -f1 -d "
> ")
> -	sumold=$(cat "$hoodfileref" 2>/dev/null | sha256sum | cut -f1 -d " ")
> +	sumnew=$(sha256sum "$hoodfiletmp" 2>/dev/null | cut -f1 -d " ")
> +	sumold=$(sha256sum "$hoodfileref" 2>/dev/null | cut -f1 -d " ")
> 
>  	json_load "$(cat "$hoodfiletmp")"
> 
> --
> 2.20.1