[pacman-dev] FS#42482 - [paccache] No candidates should not be an error

Eric Schultz eric at schultzter.ca
Tue Oct 28 02:44:51 UTC 2014

I've written a patch for this feature request, I hope this is okay.

>From c332ee7030fba07e6efe8e6635d3d1648a97ba13 Mon Sep 17 00:00:00 2001
From: Eric Schultz <eric at schultzter.ca>
Date: Mon, 27 Oct 2014 22:24:23 -0400
Subject: [PATCH] Added option to return success when there are no candidates
 for removal

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
+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=

@@ -192,6 +192,8 @@ Usage: ${myname} <operation> [options] [targets...]
     -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_LONG=('arch:' 'cachedir:' 'dryrun' 'force' 'help' 'ignore:' 'keep:'
-          'nocolor' 'remove' 'uninstalled' 'version' 'verbose' 'null')
+          'nocolor' 'noneisok' 'remove' 'uninstalled' 'version' 'verbose'

 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
  exit 1
@@ -249,6 +251,8 @@ while :; do
  shift ;;
  USE_COLOR='n' ;;
+ -n|--noneisok)
+ noneisok=1 ;;
  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

 # grab this prior to signature scavenging

Headed for the second star to the right and straight on 'til morning...

  Eric Schultz <http://schultzter.ca> (aka schultzter

  Read more at 2FatDads <http://2fatdads.com/author/schultzter/>

More information about the pacman-dev mailing list