Re: [pacman-dev] FS#42482 - [paccache] No candidates should not be an error
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@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@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@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 -- Headed for the second star to the right and straight on 'til morning... Eric Schultz <http://schultzter.ca> (aka schultzter <http://twitter.com/schultzter>) Read more at 2FatDads <http://2fatdads.com/author/schultzter/>
On 28/10/14 12:44, Eric Schultz wrote:
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@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@schultzter.ca>
D we really need an option for this? Why is having no packages to remove an error in the first place?
--- 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@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
On 28.10.2014 03:44, Eric Schultz wrote:
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=
Dan tried to link this earlier but missed the l of html so here's the link again: https://www.archlinux.org/pacman/submitting-patches.html Please use git-send-email and nothing else (especially don't paste a patch in gmail) because that is bound to break formatting as can be seen above (no indentation, wrapped lines). Also if you have any comments to add that are not part of a commit use git send-email --annotate and add them between the --- marker and the diffstat. BTT: I also don't see why paccache should exit 1. Looks like this was in the initial version Dave wrote so maybe he can chime in?
participants (3)
-
Allan McRae
-
Eric Schultz
-
Florian Pritz