1
0
mirror of https://github.com/moparisthebest/pacman synced 2025-01-09 13:07:58 -05:00

repo-add: store multi-value fields as arrays

Fields like groups and depends should be stored as arrays. This requires
rewriting our write_list_entry function to accomodate our new data type.
This new function will not write to a file, but rather only format it.

Signed-off-by: Dave Reisner <d@falconindy.com>
This commit is contained in:
Dave Reisner 2011-06-20 15:12:01 -04:00
parent 522c94f168
commit 5246fdecf6

View File

@ -84,14 +84,16 @@ This is free software; see the source for copying conditions.\n\
There is NO WARRANTY, to the extent permitted by law.\n")" There is NO WARRANTY, to the extent permitted by law.\n")"
} }
# write a list entry # format a metadata entry
# arg1 - Entry name # arg1 - Entry name
# arg2 - List # ... - value(s)
# arg3 - File to write to format_entry() {
write_list_entry() { local field=$1; shift
if [[ -n $2 ]]; then
echo "%$1%" >>$3 if [[ $1 ]]; then
echo -e $2 >>$3 printf '%%%s%%\n' "$field"
printf '%s\n' "$@"
printf '\n'
fi fi
} }
@ -224,8 +226,8 @@ verify_signature() {
db_write_entry() { db_write_entry() {
# blank out all variables # blank out all variables
local pkgfile="$1" local pkgfile="$1"
local -a _groups _licenses _replaces _depends _conflicts _provides _optdepends
local pkgname pkgver pkgdesc csize size url arch builddate packager \ local pkgname pkgver pkgdesc csize size url arch builddate packager \
_groups _licenses _replaces _depends _conflicts _provides _optdepends \
md5sum sha256sum pgpsig md5sum sha256sum pgpsig
# read info from the zipped package # read info from the zipped package
@ -237,13 +239,13 @@ db_write_entry() {
# normalize whitespace with an extglob # normalize whitespace with an extglob
declare "$var=${val//+([[:space:]])/ }" declare "$var=${val//+([[:space:]])/ }"
case "$var" in case "$var" in
group) _groups="$_groups$group\n" ;; group) _groups+=("$group") ;;
license) _licenses="$_licenses$license\n" ;; license) _licenses+=("$license") ;;
replaces) _replaces="$_replaces$replaces\n" ;; replaces) _replaces+=("$replaces") ;;
depend) _depends="$_depends$depend\n" ;; depend) _depends+=("$depend") ;;
conflict) _conflicts="$_conflicts$conflict\n" ;; conflict) _conflicts+=("$conflict") ;;
provides) _provides="$_provides$provides\n" ;; provides) _provides+=("$provides") ;;
optdepend) _optdepends="$_optdepends$optdepend\n" ;; optdepend) _optdepends+=("$optdepend") ;;
esac esac
done< <(bsdtar -xOqf "$pkgfile" .PKGINFO) done< <(bsdtar -xOqf "$pkgfile" .PKGINFO)
@ -297,7 +299,7 @@ db_write_entry() {
[[ -n $pkgbase ]] && echo -e "%BASE%\n$pkgbase\n" >>desc [[ -n $pkgbase ]] && echo -e "%BASE%\n$pkgbase\n" >>desc
echo -e "%VERSION%\n$pkgver\n" >>desc echo -e "%VERSION%\n$pkgver\n" >>desc
[[ -n $pkgdesc ]] && echo -e "%DESC%\n$pkgdesc\n" >>desc [[ -n $pkgdesc ]] && echo -e "%DESC%\n$pkgdesc\n" >>desc
write_list_entry "GROUPS" "$_groups" "desc" format_entry "GROUPS" "${_groups[@]}" >>"desc"
[[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc [[ -n $csize ]] && echo -e "%CSIZE%\n$csize\n" >>desc
[[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc [[ -n $size ]] && echo -e "%ISIZE%\n$size\n" >>desc
@ -309,20 +311,20 @@ db_write_entry() {
[[ -n $pgpsig ]] && echo -e "%PGPSIG%\n$pgpsig\n" >>desc [[ -n $pgpsig ]] && echo -e "%PGPSIG%\n$pgpsig\n" >>desc
[[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc [[ -n $url ]] && echo -e "%URL%\n$url\n" >>desc
write_list_entry "LICENSE" "$_licenses" "desc" format_entry "LICENSE" "${_licenses[@]}" >>"desc"
[[ -n $arch ]] && echo -e "%ARCH%\n$arch\n" >>desc [[ -n $arch ]] && echo -e "%ARCH%\n$arch\n" >>desc
[[ -n $builddate ]] && echo -e "%BUILDDATE%\n$builddate\n" >>desc [[ -n $builddate ]] && echo -e "%BUILDDATE%\n$builddate\n" >>desc
[[ -n $packager ]] && echo -e "%PACKAGER%\n$packager\n" >>desc [[ -n $packager ]] && echo -e "%PACKAGER%\n$packager\n" >>desc
write_list_entry "REPLACES" "$_replaces" "desc" format_entry "REPLACES" "${_replaces[@]}" >>"desc"
# create depends entry # create depends entry
msg2 "$(gettext "Creating '%s' db entry...")" 'depends' msg2 "$(gettext "Creating '%s' db entry...")" 'depends'
# create the file even if it will remain empty {
touch "depends" format_entry "DEPENDS" "${_depends[@]}"
write_list_entry "DEPENDS" "$_depends" "depends" format_entry "CONFLICTS" "${_conflicts[@]}"
write_list_entry "CONFLICTS" "$_conflicts" "depends" format_entry "PROVIDES" "${_provides[@]}"
write_list_entry "PROVIDES" "$_provides" "depends" format_entry "OPTDEPENDS" "${_optdepends[@]}"
write_list_entry "OPTDEPENDS" "$_optdepends" "depends" } >'depends'
popd >/dev/null popd >/dev/null
popd >/dev/null popd >/dev/null