[pacman-contrib] [PATCH] Migrate scripts from manual parsing of pacman.conf, to use of pacman-conf

Eli Schwartz eschwartz at archlinux.org
Wed Feb 14 16:54:44 UTC 2018


pacman.conf cannot be properly parsed in bash, e.g. it fails to handle
`Include = ` directives, hence why pacman introduced a configuration
parsing tool in the first place.

Signed-off-by: Eli Schwartz <eschwartz at archlinux.org>
---

v2: Forgot to remove the get_cachedirs_from_config function.
Also fix typo in CacheDir.

 src/checkupdates.sh.in |  2 +-
 src/paccache.sh.in     | 17 +----------------
 src/pacdiff.sh.in      |  4 +---
 3 files changed, 3 insertions(+), 20 deletions(-)

diff --git a/src/checkupdates.sh.in b/src/checkupdates.sh.in
index 9f34dc1..1d01fda 100644
--- a/src/checkupdates.sh.in
+++ b/src/checkupdates.sh.in
@@ -46,7 +46,7 @@ fi
 
 trap 'rm -f $CHECKUPDATES_DB/db.lck' INT TERM EXIT
 
-DBPath="$(awk -F' *= *' '/^DBPath/ { print $2 }' @sysconfdir@/pacman.conf)"
+DBPath="$(pacman-conf DBPath)"
 if [[ -z "$DBPath" ]] || [[ ! -d "$DBPath" ]]; then
 	DBPath="@localstatedir@/lib/pacman/"
 fi
diff --git a/src/paccache.sh.in b/src/paccache.sh.in
index 143c6e3..49680be 100644
--- a/src/paccache.sh.in
+++ b/src/paccache.sh.in
@@ -40,20 +40,6 @@ die() {
 	exit 1
 }
 
-get_cachedirs_from_config() {
-	local key value ret
-
-	ret=1
-	while IFS=$'= \t' read -r key value _; do
-		if [[ $key = CacheDir ]]; then
-			echo "$value"
-			ret=0
-		fi
-	done <"$1"
-
-	return $ret
-}
-
 # reads a list of files on stdin and prints out deletion candidates
 pkgfilter() {
 	# there's whitelist and blacklist parameters passed to this
@@ -287,8 +273,7 @@ m4_include(../lib/term_colors.sh)
 
 # setting default cachedirs
 if [[ -z $cachedirs ]]; then
-	cachedir="$(get_cachedirs_from_config "@sysconfdir@/pacman.conf")"
-	cachedirs=("${cachedirs[@]:- at localstatedir@/cache/pacman/pkg}")
+	cachedirs=($(pacman-conf CacheDir))
 fi
 
 # remaining args are a whitelist
diff --git a/src/pacdiff.sh.in b/src/pacdiff.sh.in
index ef385c2..866932d 100644
--- a/src/pacdiff.sh.in
+++ b/src/pacdiff.sh.in
@@ -130,12 +130,10 @@ case $(( USE_FIND + USE_LOCATE + USE_PACDB )) in
 esac
 
 if (( USE_PACDB )); then
-	if [[ ! -r @sysconfdir@/pacman.conf ]]; then
+	if ! DBPath="$(pacman-conf DBPath)"; then
 		error "unable to read @sysconfdir@/pacman.conf"
 		usage; exit 1
 	fi
-
-	eval $(awk '/DBPath/ {print $1$2$3}' @sysconfdir@/pacman.conf)
 	pac_db="${DBPath:- at localstatedir@/lib/pacman/}local"
 	if [[ ! -d "${pac_db}" ]]; then
 		error "unable to read pacman database %s". "${pac_db}"
-- 
2.16.1


More information about the pacman-contrib mailing list