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

Allan McRae allan at archlinux.org
Tue Oct 28 07:04:02 UTC 2014


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

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


More information about the pacman-dev mailing list