[pacman-dev] bash-3 only error trap activation

Allan McRae allan at archlinux.org
Tue Jun 22 01:00:18 EDT 2010


On 22/06/10 14:23, Andres P wrote:
> Ok, after actually taking the time to install bash3...
>
> $ env -i HOME="$HOME" TERM="$TERM" bash3<<\!
>
>    set -o errexit
>    set -o errtrace
>
>    TRIGGERED_ERR() { return $?; }
>
>    trap 'TRIGGERED_ERR' ERR
>
>    set -o xtrace
>
>    var=$(false) || true
>    echo $?
>
>    var=$(false || true) # only way of not triggering it...
>    echo $?
>
> !
>
> ++ false           # Subshell false
> +++ TRIGGERED_ERR  # Ignores outer "|| true"
> +++ return 1
> + var=
> + true
> + echo 0
> 0                  # But the entire command line does
>                     # not set off errexit
> ++ false
> ++ true            # Predictable second subshell...
> + var=
> + echo 0
> 0
>
>
> So, if you want to keep the ERR trap then you'll have to modify check_deps so
> that it always returns true.
>
> Then you'd have to parse its output, similar to how in_opt_array works.
>
>
> Horrible kludge, lets drop set -E.
>

I do not think that dropping 'set -E' completely is the way to go. Just 
dropping it around that pacman call is enough.

This is the diff I am proposing:

@@ -382,11 +382,15 @@
  }

  check_deps() {
-	(( $# > 0 )) || return
+	(( $# > 0 )) || return 0

+	# Disable error trap in pacman subshell call as this breaks bash-3.2 
compatibility
+	# Also, a non-zero return value is not unexpected and we are manually 
dealing them
+ 	set +E
  	local ret=0
-	pmout=$(run_pacman -T "$@")
-	ret=$?
+	pmout=$(run_pacman -T "$@") || ret=$?
+	set -E
+
  	if (( ret == 127 )); then #unresolved deps
  		echo "$pmout"
  	elif (( ret )); then


Allan


More information about the pacman-dev mailing list