[pacman-dev] [PATCH 1/2] read cachedir from config file

Andrew Gregory andrew.gregory.8 at gmail.com
Tue Jun 24 17:09:28 EDT 2014


On 06/24/14 at 04:32pm, Dave Reisner wrote:
> ---
>  contrib/paccache.sh.in | 20 +++++++++++++++++---
>  1 file changed, 17 insertions(+), 3 deletions(-)

The default should be left in so this doesn't die if no CacheDir is
specified in pacman.conf and the user doesn't provide one on the
command-line:

 $ ./paccache -d
 ==> ERROR: cachedir '' does not exist or is not a directory

apg

> diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
> index 039ac8a..57c0458 100644
> --- a/contrib/paccache.sh.in
> +++ b/contrib/paccache.sh.in
> @@ -25,7 +25,7 @@ declare -r myver='@PACKAGE_VERSION@'
>  
>  declare -a candidates=() cmdopts=() whitelist=() blacklist=()
>  declare -i delete=0 dryrun=0 filecount=0 move=0 needsroot=0 totalsaved=0 verbose=0
> -declare    cachedir=@localstatedir@/cache/pacman/pkg delim=$'\n' keep=3 movedir= scanarch=
> +declare    cachedir= delim=$'\n' keep=3 movedir= scanarch=
>  
>  USE_COLOR='y'
>  
> @@ -37,6 +37,19 @@ die() {
>  	exit 1
>  }
>  
> +get_cachedir_from_config() {
> +	local key value
> +
> +	while IFS=$'= \t' read -r key value _; do
> +		if [[ $key = CacheDir ]]; then
> +			echo "$value"
> +			return 0
> +		fi
> +	done <"$1"
> +
> +	return 1
> +}
> +
>  # reads a list of files on stdin and prints out deletion candidates
>  pkgfilter() {
>  	# there's whitelist and blacklist parameters passed to this
> @@ -165,8 +178,7 @@ Usage: ${myname} <operation> [options] [targets...]
>  
>    Options:
>      -a, --arch <arch>     scan for "arch" (default: all architectures).
> -    -c, --cachedir <dir>  scan "dir" for packages.
> -                          (default: @localstatedir@/cache/pacman/pkg).
> +    -c, --cachedir <dir>  scan "dir" for packages. (default: $cachedir).
>      -f, --force           apply force to mv(1) and rm(1) operations.
>      -h, --help            display this help message and exit.
>      -i, --ignore <pkgs>   ignore "pkgs", comma-separated. Alternatively, specify
> @@ -191,6 +203,8 @@ OPT_SHORT=':a:c:dfhi:k:m:rsuVvz'
>  OPT_LONG=('arch:' 'cachedir:' 'dryrun' 'force' 'help' 'ignore:' 'keep:' 'move'
>            'nocolor' 'remove' 'uninstalled' 'version' 'verbose' 'null')
>  
> +cachedir=$(get_cachedir_from_config "@sysconfdir@/pacman.conf")
> +
>  if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
>  	exit 1
>  fi
> -- 
> 2.0.0


More information about the pacman-dev mailing list