[pacman-dev] [PATCH] Added option to return success when there are no candidates for removal

Eric Schultz eric at schultzter.ca
Tue Oct 28 19:35:04 UTC 2014


Add the -n or --noneisok option to return success if there are no candidates
for removal. This is useful when checking the exit code, like from a systemd
unit, and it is okay when there are no packages to remove.

Signed-off-by: Eric Schultz <eric at schultzter.ca>
---
 contrib/paccache.sh.in | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)

diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
index 71aee23..cf1ba15 100644
--- a/contrib/paccache.sh.in
+++ b/contrib/paccache.sh.in
@@ -24,7 +24,7 @@ declare -r myname='paccache'
 declare -r myver='@PACKAGE_VERSION@'
 
 declare -a cachedirs=() candidates=() cmdopts=() whitelist=() blacklist=()
-declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 totalsaved=0 verbose=0
+declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 noneisok=0 totalsaved=0 verbose=0
 declare    delim=$'\n' keep=3 movedir= scanarch=
 
 USE_COLOR='y'
@@ -192,6 +192,8 @@ Usage: ${myname} <operation> [options] [targets...]
                           delimited.
     -k, --keep <num>      keep "num" of each package in the cache (default: 3).
         --nocolor         remove color from output.
+		-n, --noneisok				returns 0 (no error) rather than 1 (failed) when there
+													are no candidate packages for removal
     -u, --uninstalled     target uninstalled packages.
     -v, --verbose         increase verbosity. specify up to 3 times.
     -z, --null            use null delimiters for candidate names (only with -v
@@ -205,9 +207,9 @@ version() {
 	echo 'Copyright (C) 2011 Dave Reisner <dreisner at archlinux.org>'
 }
 
-OPT_SHORT=':a:c:dfhi:k:m:rsuVvz'
+OPT_SHORT=':a:c:dfhi:k:m:nrsuVvz'
 OPT_LONG=('arch:' 'cachedir:' 'dryrun' 'force' 'help' 'ignore:' 'keep:' 'move'
-          'nocolor' 'remove' 'uninstalled' 'version' 'verbose' 'null')
+          'nocolor' 'noneisok' 'remove' 'uninstalled' 'version' 'verbose' 'null')
 
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
 	exit 1
@@ -249,6 +251,8 @@ while :; do
 			shift ;;
 		--nocolor)
 			USE_COLOR='n' ;;
+		-n|--noneisok)
+			noneisok=1 ;;
 		-m|--move)
 			move=1 movedir=$2
 			shift ;;
@@ -328,7 +332,11 @@ done
 
 if (( ! ${#candidates[*]} )); then
 	msg 'no candidate packages found for pruning'
-	exit 1
+	if (( noneisok )); then
+		exit 0
+	else
+		exit 1
+	fi
 fi
 
 # grab this prior to signature scavenging
-- 
2.1.2


More information about the pacman-dev mailing list