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 07-09-2011, 02:40 AM
Dave Reisner
 
Default pacman-key: refactor get_from

This function had a variety of pitfalls, including the inability to
successfully find a key=value pair where no whitespace surrounded the
equals sign. Make it more robust by splitting the line on the equals
itself, and performing whitespace trimming on the resulting key/value
pair.

Signed-off-by: Dave Reisner <dreisner@archlinux.org>
---
scripts/pacman-key.sh.in | 18 ++++++++++--------
1 files changed, 10 insertions(+), 8 deletions(-)

diff --git a/scripts/pacman-key.sh.in b/scripts/pacman-key.sh.in
index b884870..9fae0d8 100644
--- a/scripts/pacman-key.sh.in
+++ b/scripts/pacman-key.sh.in
@@ -74,17 +74,19 @@ This is free software; see the source for copying conditions.

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

-# Read provided file and search for values matching the given key
-# The contents of the file are expected to be in this format: key = value
-# 'key', 'equal sign' and 'value' can be surrounded by random whitespace
-# Usage: get_from "$file" "$key" # returns the value for the first matching key in the file
+# read the config file "$1" which has key=value pairs, and return the key which
+# matches "$2". the equals sign between pairs may be surrounded by any amount
+# of whitespace.
get_from() {
- while read key _ value; do
- if [[ $key = $2 ]]; then
- echo "$value"
- break
+ while IFS='=' read -r key value; do
+ [[ -z $key || ${key:0:1} = '#' ]] && continue
+
+ if [[ ${key%% *} = "$2" && -n ${value##* } ]]; then
+ echo "${value##* }"
+ return 0
fi
done < "$1"
+ return 1
}

reload_keyring() {
--
1.7.6
 
Old 07-09-2011, 03:11 AM
Allan McRae
 
Default pacman-key: refactor get_from

On 09/07/11 12:40, Dave Reisner wrote:

This function had a variety of pitfalls, including the inability to
successfully find a key=value pair where no whitespace surrounded the
equals sign. Make it more robust by splitting the line on the equals
itself, and performing whitespace trimming on the resulting key/value
pair.

Signed-off-by: Dave Reisner<dreisner@archlinux.org>


Signed-off-by: Allan

Pulled onto my working branch with the rest of the pacman-key stuff.

Allan
 

Thread Tools




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

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