FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 06-20-2011, 07:46 PM
Dave Reisner
 
Default 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>
---
scripts/repo-add.sh.in | 46 +++++++++++++++++++++++++---------------------
1 files changed, 25 insertions(+), 21 deletions(-)

diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 3783348..fb1e24a 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -82,14 +82,16 @@ This is free software; see the source for copying conditions.

There is NO WARRANTY, to the extent permitted by law.
")"
}

-# write a list entry
+# format a metadata entry
# arg1 - Entry name
-# arg2 - List
-# arg3 - File to write to
-write_list_entry() {
- if [[ -n $2 ]]; then
- echo "%$1%" >>$3
- echo -e $2 >>$3
+# ... - value(s)
+format_entry() {
+ local field=$1; shift
+
+ if [[ $1 ]]; then
+ printf '%%%s%%
' "$field"
+ printf '%s
' "$@"
+ printf '
'
fi
}

@@ -237,13 +239,13 @@ db_write_entry()
IFS=' =' read -r var val < <(printf '%s
' "$line")
declare "$var=$val"
case "$var" in
- group) _groups="$_groups$group
" ;;
- license) _licenses="$_licenses$license
" ;;
- replaces) _replaces="$_replaces$replaces
" ;;
- depend) _depends="$_depends$depend
" ;;
- conflict) _conflicts="$_conflicts$conflict
" ;;
- provides) _provides="$_provides$provides
" ;;
- optdepend) _optdepends="$_optdepends$optdepend
" ;;
+ group) _groups+=("$group") ;;
+ license) _licenses+=("$license") ;;
+ replaces) _replaces+=("$replaces") ;;
+ depend) _depends+=("$depend") ;;
+ conflict) _conflicts+=("$conflict") ;;
+ provides) _provides+=("$provides") ;;
+ optdepend) _optdepends+=("$optdepend") ;;
esac
done< <(bsdtar -xOqf "$pkgfile" .PKGINFO)

@@ -297,7 +299,7 @@ db_write_entry()
[[ -n $pkgbase ]] && echo -e "%BASE%
$pkgbase
" >>desc
echo -e "%VERSION%
$pkgver
" >>desc
[[ -n $pkgdesc ]] && echo -e "%DESC%
$pkgdesc
" >>desc
- write_list_entry "GROUPS" "$_groups" "desc"
+ format_entry "GROUPS" "${_groups[@]}" >>"desc"
[[ -n $csize ]] && echo -e "%CSIZE%
$csize
" >>desc
[[ -n $size ]] && echo -e "%ISIZE%
$size
" >>desc

@@ -309,20 +311,22 @@ db_write_entry()
[[ -n $pgpsig ]] && echo -e "%PGPSIG%
$pgpsig
" >>desc

[[ -n $url ]] && echo -e "%URL%
$url
" >>desc
- write_list_entry "LICENSE" "$_licenses" "desc"
+ format_entry "LICENSE" "${_licenses[@]}" >>"desc"
[[ -n $arch ]] && echo -e "%ARCH%
$arch
" >>desc
[[ -n $builddate ]] && echo -e "%BUILDDATE%
$builddate
" >>desc
[[ -n $packager ]] && echo -e "%PACKAGER%
$packager
" >>desc
- write_list_entry "REPLACES" "$_replaces" "desc"
+ format_entry "REPLACES" "${_replaces[@]}" >>"desc"

# create depends entry
msg2 "$(gettext "Creating '%s' db entry...")" 'depends'
# create the file even if it will remain empty
touch "depends"
- write_list_entry "DEPENDS" "$_depends" "depends"
- write_list_entry "CONFLICTS" "$_conflicts" "depends"
- write_list_entry "PROVIDES" "$_provides" "depends"
- write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
+ {
+ format_entry "DEPENDS" "${_depends[@]}"
+ format_entry "CONFLICTS" "${_conflicts[@]}"
+ format_entry "PROVIDES" "${_provides[@]}"
+ format_entry "OPTDEPENDS" "${_optdepends[@]}"
+ } >>'depends'

popd >/dev/null
popd >/dev/null
--
1.7.5.4
 
Old 06-21-2011, 05:21 PM
Dan McGee
 
Default repo-add: store multi-value fields as arrays

On Mon, Jun 20, 2011 at 2:46 PM, Dave Reisner <d@falconindy.com> wrote:
> 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>
Signed-off-by: Dan McGee <dan@archlinux.org>

> ---
> *scripts/repo-add.sh.in | * 46 +++++++++++++++++++++++++---------------------
> *1 files changed, 25 insertions(+), 21 deletions(-)
>
> diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
> index 3783348..fb1e24a 100644
> --- a/scripts/repo-add.sh.in
> +++ b/scripts/repo-add.sh.in
> @@ -82,14 +82,16 @@ This is free software; see the source for copying conditions.

> *There is NO WARRANTY, to the extent permitted by law.
")"
> *}
>
> -# write a list entry
> +# format a metadata entry
> *# * * * * * * *arg1 - Entry name
> -# * * * * * * *arg2 - List
> -# * * * * * * *arg3 - File to write to
> -write_list_entry() {
> - * * * if [[ -n $2 ]]; then
> - * * * * * * * echo "%$1%" >>$3
> - * * * * * * * echo -e $2 >>$3
> +# * * * * * * *... *- value(s)
> +format_entry() {
> + * * * local field=$1; shift
> +
> + * * * if [[ $1 ]]; then
> + * * * * * * * printf '%%%s%%
' "$field"
> + * * * * * * * printf '%s
' "$@"
> + * * * * * * * printf '
'
> * * * *fi
> *}
>
> @@ -237,13 +239,13 @@ db_write_entry()
> * * * * * * * *IFS=' =' read -r var val < <(printf '%s
' "$line")
> * * * * * * * *declare "$var=$val"
> * * * * * * * *case "$var" in
> - * * * * * * * * * * * group) * *_groups="$_groups$group
" ;;
> - * * * * * * * * * * * license) *_licenses="$_licenses$license
" ;;
> - * * * * * * * * * * * replaces) _replaces="$_replaces$replaces
" ;;
> - * * * * * * * * * * * depend) * _depends="$_depends$depend
" ;;
> - * * * * * * * * * * * conflict) _conflicts="$_conflicts$conflict
" ;;
> - * * * * * * * * * * * provides) _provides="$_provides$provides
" ;;
> - * * * * * * * * * * * optdepend) _optdepends="$_optdepends$optdepend
" ;;
> + * * * * * * * * * * * group) * * _groups+=("$group") ;;
> + * * * * * * * * * * * license) * _licenses+=("$license") ;;
> + * * * * * * * * * * * replaces) *_replaces+=("$replaces") ;;
> + * * * * * * * * * * * depend) * *_depends+=("$depend") ;;
> + * * * * * * * * * * * conflict) *_conflicts+=("$conflict") ;;
> + * * * * * * * * * * * provides) *_provides+=("$provides") ;;
> + * * * * * * * * * * * optdepend) _optdepends+=("$optdepend") ;;
> * * * * * * * *esac
> * * * *done< <(bsdtar -xOqf "$pkgfile" .PKGINFO)
>
> @@ -297,7 +299,7 @@ db_write_entry()
> * * * *[[ -n $pkgbase ]] && echo -e "%BASE%
$pkgbase
" >>desc
> * * * *echo -e "%VERSION%
$pkgver
" >>desc
> * * * *[[ -n $pkgdesc ]] && echo -e "%DESC%
$pkgdesc
" >>desc
> - * * * write_list_entry "GROUPS" "$_groups" "desc"
> + * * * format_entry "GROUPS" "${_groups[@]}" >>"desc"
> * * * *[[ -n $csize ]] && echo -e "%CSIZE%
$csize
" >>desc
> * * * *[[ -n $size ]] && echo -e "%ISIZE%
$size
" >>desc
>
> @@ -309,20 +311,22 @@ db_write_entry()
> * * * *[[ -n $pgpsig ]] && echo -e "%PGPSIG%
$pgpsig
" >>desc
>
> * * * *[[ -n $url ]] && echo -e "%URL%
$url
" >>desc
> - * * * write_list_entry "LICENSE" "$_licenses" "desc"
> + * * * format_entry "LICENSE" "${_licenses[@]}" >>"desc"
> * * * *[[ -n $arch ]] && echo -e "%ARCH%
$arch
" >>desc
> * * * *[[ -n $builddate ]] && echo -e "%BUILDDATE%
$builddate
" >>desc
> * * * *[[ -n $packager ]] && echo -e "%PACKAGER%
$packager
" >>desc
> - * * * write_list_entry "REPLACES" "$_replaces" "desc"
> + * * * format_entry "REPLACES" "${_replaces[@]}" >>"desc"
>
> * * * *# create depends entry
> * * * *msg2 "$(gettext "Creating '%s' db entry...")" 'depends'
> * * * *# create the file even if it will remain empty
> * * * *touch "depends"
> - * * * write_list_entry "DEPENDS" "$_depends" "depends"
> - * * * write_list_entry "CONFLICTS" "$_conflicts" "depends"
> - * * * write_list_entry "PROVIDES" "$_provides" "depends"
> - * * * write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
> + * * * {
> + * * * * * * * format_entry "DEPENDS" "${_depends[@]}"
> + * * * * * * * format_entry "CONFLICTS" "${_conflicts[@]}"
> + * * * * * * * format_entry "PROVIDES" "${_provides[@]}"
> + * * * * * * * format_entry "OPTDEPENDS" "${_optdepends[@]}"
> + * * * } >>'depends'
>
> * * * *popd >/dev/null
> * * * *popd >/dev/null
> --
> 1.7.5.4
>
>
>
 
Old 06-23-2011, 12:38 AM
Dave Reisner
 
Default 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>
---
scripts/repo-add.sh.in | 50 ++++++++++++++++++++++++-----------------------
1 files changed, 26 insertions(+), 24 deletions(-)

diff --git a/scripts/repo-add.sh.in b/scripts/repo-add.sh.in
index 01eeb84..8350db5 100644
--- a/scripts/repo-add.sh.in
+++ b/scripts/repo-add.sh.in
@@ -84,14 +84,16 @@ This is free software; see the source for copying conditions.

There is NO WARRANTY, to the extent permitted by law.
")"
}

-# write a list entry
+# format a metadata entry
# arg1 - Entry name
-# arg2 - List
-# arg3 - File to write to
-write_list_entry() {
- if [[ -n $2 ]]; then
- echo "%$1%" >>$3
- echo -e $2 >>$3
+# ... - value(s)
+format_entry() {
+ local field=$1; shift
+
+ if [[ $1 ]]; then
+ printf '%%%s%%
' "$field"
+ printf '%s
' "$@"
+ printf '
'
fi
}

@@ -224,8 +226,8 @@ verify_signature() {
db_write_entry() {
# blank out all variables
local pkgfile="$1"
+ local -a _groups _licenses _replaces _depends _conflicts _provides _optdepends
local pkgname pkgver pkgdesc csize size url arch builddate packager
- _groups _licenses _replaces _depends _conflicts _provides _optdepends
md5sum sha256sum pgpsig

# read info from the zipped package
@@ -235,13 +237,13 @@ db_write_entry() {
IFS=' =' read -r var val < <(printf '%s
' "$line")
declare "$var=${val//+([[:space:]])/ }" # normalize whitespace
case "$var" in
- group) _groups="$_groups$group
" ;;
- license) _licenses="$_licenses$license
" ;;
- replaces) _replaces="$_replaces$replaces
" ;;
- depend) _depends="$_depends$depend
" ;;
- conflict) _conflicts="$_conflicts$conflict
" ;;
- provides) _provides="$_provides$provides
" ;;
- optdepend) _optdepends="$_optdepends$optdepend
" ;;
+ group) _groups+=("$group") ;;
+ license) _licenses+=("$license") ;;
+ replaces) _replaces+=("$replaces") ;;
+ depend) _depends+=("$depend") ;;
+ conflict) _conflicts+=("$conflict") ;;
+ provides) _provides+=("$provides") ;;
+ optdepend) _optdepends+=("$optdepend") ;;
esac
done< <(bsdtar -xOqf "$pkgfile" .PKGINFO)

@@ -295,7 +297,7 @@ db_write_entry() {
[[ -n $pkgbase ]] && echo -e "%BASE%
$pkgbase
" >>desc
echo -e "%VERSION%
$pkgver
" >>desc
[[ -n $pkgdesc ]] && echo -e "%DESC%
$pkgdesc
" >>desc
- write_list_entry "GROUPS" "$_groups" "desc"
+ format_entry "GROUPS" "${_groups[@]}" >>"desc"
[[ -n $csize ]] && echo -e "%CSIZE%
$csize
" >>desc
[[ -n $size ]] && echo -e "%ISIZE%
$size
" >>desc

@@ -307,20 +309,20 @@ db_write_entry() {
[[ -n $pgpsig ]] && echo -e "%PGPSIG%
$pgpsig
" >>desc

[[ -n $url ]] && echo -e "%URL%
$url
" >>desc
- write_list_entry "LICENSE" "$_licenses" "desc"
+ format_entry "LICENSE" "${_licenses[@]}" >>"desc"
[[ -n $arch ]] && echo -e "%ARCH%
$arch
" >>desc
[[ -n $builddate ]] && echo -e "%BUILDDATE%
$builddate
" >>desc
[[ -n $packager ]] && echo -e "%PACKAGER%
$packager
" >>desc
- write_list_entry "REPLACES" "$_replaces" "desc"
+ format_entry "REPLACES" "${_replaces[@]}" >>"desc"

# create depends entry
msg2 "$(gettext "Creating '%s' db entry...")" 'depends'
- # create the file even if it will remain empty
- touch "depends"
- write_list_entry "DEPENDS" "$_depends" "depends"
- write_list_entry "CONFLICTS" "$_conflicts" "depends"
- write_list_entry "PROVIDES" "$_provides" "depends"
- write_list_entry "OPTDEPENDS" "$_optdepends" "depends"
+ {
+ format_entry "DEPENDS" "${_depends[@]}"
+ format_entry "CONFLICTS" "${_conflicts[@]}"
+ format_entry "PROVIDES" "${_provides[@]}"
+ format_entry "OPTDEPENDS" "${_optdepends[@]}"
+ } >'depends'

popd >/dev/null
popd >/dev/null
--
1.7.5.4
 

Thread Tools




All times are GMT. The time now is 10:01 PM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org