From 7c4dad7d8b56c5bc3eaa500f45a6c17ff2d1a593 Mon Sep 17 00:00:00 2001 From: Dan Nicholson Date: Sat, 4 Feb 2012 09:42:23 -0800 Subject: [PATCH] cnf: Return errors immediately instead of storing return values Instead of storing return values and logic in local variables, just return immediately if we can't search the database. If we can run the search command, let its exit code be the return code for the function. --- contrib/command-not-found/PackageKit.sh.in | 19 +++++-------------- 1 files changed, 5 insertions(+), 14 deletions(-) diff --git a/contrib/command-not-found/PackageKit.sh.in b/contrib/command-not-found/PackageKit.sh.in index 3097a39..6960cf4 100644 --- a/contrib/command-not-found/PackageKit.sh.in +++ b/contrib/command-not-found/PackageKit.sh.in @@ -7,8 +7,6 @@ # (at your option) any later version. command_not_found_handle () { - local runcnf=1 - local retval=127 local fmt # inform the user of the missing command @@ -16,21 +14,14 @@ command_not_found_handle () { printf "%s: $fmt\n" "$0" "$1" # only search for the command if we're interactive - [[ $- =~ i ]] || runcnf=0 + [[ $- =~ i ]] || return 127 # don't run if DBus isn't running - [ ! -S /var/run/dbus/system_bus_socket ] && runcnf=0 + [ ! -S /var/run/dbus/system_bus_socket ] && return 127 # don't run if packagekitd doesn't exist in the _system_ root - [ ! -x /usr/libexec/packagekitd ] && runcnf=0 + [ ! -x /usr/libexec/packagekitd ] && return 127 - # run the command, or just print a warning - if [ $runcnf -eq 1 ]; then - @LIBEXECDIR@/pk-command-not-found "$@" - retval=$? - fi - - # return success or failure - return $retval + # run the command + @LIBEXECDIR@/pk-command-not-found "$@" } - -- 1.7.7.6