[pacman-dev] [PATCH 1/3] repo-add: bashify reading of .PKGINFO file

Dave Reisner d at falconindy.com
Mon Jun 20 15:46:32 EDT 2011


grep and sed aren't needed here, and this removes the truly ugly
manipulation of IFS. The process substituion could just as well be a
herestring, but it breaks vim's syntax highlighting. Style over
substance, mang.

Signed-off-by: Dave Reisner <d at falconindy.com>
---
 scripts/repo-add.sh.in |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 14506dc..3783348 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -230,19 +230,12 @@ db_write_entry()
 		_groups _licenses _replaces _depends _conflicts _provides _optdepends \
 		md5sum sha256sum pgpsig
 
-	local OLDIFS="$IFS"
-	# IFS (field separator) is only the newline character
-	IFS="
-"
-
 	# read info from the zipped package
 	local line var val
-	for line in $(bsdtar -xOqf "$pkgfile" .PKGINFO |
-			grep -v '^#' | sed 's|\(\w*\)\s*=\s*\(.*\)|\1 \2|'); do
-		# bash awesomeness here- var is always one word, val is everything else
-		var=${line%% *}
-		val=${line#* }
-		declare $var="$val"
+	while read -r line; do
+		[[ ${line:0:1} = '#' ]] && continue
+		IFS=' =' read -r var val < <(printf '%s\n' "$line")
+		declare "$var=$val"
 		case "$var" in
 			group)    _groups="$_groups$group\n" ;;
 			license)  _licenses="$_licenses$license\n" ;;
@@ -252,9 +245,7 @@ db_write_entry()
 			provides) _provides="$_provides$provides\n" ;;
 			optdepend) _optdepends="$_optdepends$optdepend\n" ;;
 		esac
-	done
-
-	IFS=$OLDIFS
+	done< <(bsdtar -xOqf "$pkgfile" .PKGINFO)
 
 	csize=$(@SIZECMD@ "$pkgfile")
 
-- 
1.7.5.4



More information about the pacman-dev mailing list