[pacman-dev] [PATCH] paccache: read default cachedir from pacman.conf

Dave Reisner dreisner at archlinux.org
Sun Aug 10 09:41:31 EDT 2014


Implements FS#40738.
---
Sorry, last patch is broke when pacman.conf has no CacheDir defined...

 contrib/paccache.sh.in | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/contrib/paccache.sh.in b/contrib/paccache.sh.in
index 039ac8a..b9620a1 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,10 @@ OPT_SHORT=':a:c:dfhi:k:m:rsuVvz'
 OPT_LONG=('arch:' 'cachedir:' 'dryrun' 'force' 'help' 'ignore:' 'keep:' 'move'
           'nocolor' 'remove' 'uninstalled' 'version' 'verbose' 'null')
 
+if ! cachedir=$(get_cachedir_from_config "@sysconfdir@/pacman.conf"); then
+	cachedir=@localstatedir@/cache/pacman/pkg
+fi
+
 if ! parseopts "$OPT_SHORT" "${OPT_LONG[@]}" -- "$@"; then
 	exit 1
 fi
-- 
2.0.4


More information about the pacman-dev mailing list