[devtools,v2,2/2] makechrootpkg: Fix anti-pattern when checking for enabled features

Message ID 20170903075340.13311-2-eschwartz@archlinux.org
State Accepted
Headers show
Series [devtools,v2,1/2] makechrootpkg: Fix unconditionally running namcap | expand

Commit Message

Eli Schwartz Sept. 3, 2017, 7:53 a.m. UTC
Don't use error-prone logic e.g.
foo=true; if $foo ...

This completely fails to act as expected when the variable is unset
because of unrelated bugs.

While this merely causes the default behavior to be "false" rather than
"true" in such cases, it is better to fail to enable explicitly
requested behavior (which will be noticed by the user) than to simply
upgrade to this behavior for free (which may not seem to have any
obvious cause).

Signed-off-by: Eli Schwartz <eschwartz@archlinux.org>
---

v2: somewhat more accurate commit message

 makechrootpkg.in | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Patch

diff --git a/makechrootpkg.in b/makechrootpkg.in
index fe9410d..ebea171 100644
--- a/makechrootpkg.in
+++ b/makechrootpkg.in
@@ -188,7 +188,7 @@  prepare_chroot() {
 	local keepbuilddir=$3
 	local run_namcap=$4
 
-	$keepbuilddir || rm -rf "$copydir/build"
+	[[ $keepbuilddir = true ]] || rm -rf "$copydir/build"
 
 	local builduser_uid builduser_gid
 	builduser_uid="${SUDO_UID:-$UID}"
@@ -230,7 +230,7 @@  EOF
 		declare -f _chrootbuild
 		printf '_chrootbuild "$@" || exit\n'
 
-		if $run_namcap; then
+		if [[ $run_namcap = true ]]; then
 			declare -f _chrootnamcap
 			printf '_chrootnamcap || exit\n'
 		fi