From a19597b2beb95ac615b515607dc56490586e6222 Mon Sep 17 00:00:00 2001 From: "graham.gower" Date: Thu, 3 Dec 2009 04:11:26 +0000 Subject: [PATCH] Two fixes from Martin Jansa . * if there are more alternatives with highest priority, use the one last in alternatives file (latest installed) * if target exists and is a directory, remove link, otherwise new alternative link is created inside that direstory git-svn-id: http://opkg.googlecode.com/svn/trunk@439 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358 --- utils/update-alternatives.in | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/utils/update-alternatives.in b/utils/update-alternatives.in index a49cc09..34d89f1 100644 --- a/utils/update-alternatives.in +++ b/utils/update-alternatives.in @@ -95,10 +95,8 @@ find_best_alt() { link=$OPKG_OFFLINE_ROOT/`head -n 1 $ad/$name` -## path=`sed -ne "1!p" $ad/$name | sort -nr -k2 | head -1 | sed 's/ .*//'` -## busybox safe: - path=`sed -ne "1!p" $ad/$name | sed -e "s/\(.*\) \(.*\)/\2 \1/g" | sort -nr | head -n 1 | sed 's/[^ ]* //'` - if [ -z "$path" ]; then + prio=`sed -ne "1!p" $ad/$name | sed -e "s/\(.*\) \(.*\)/\2 \1/g" | sort -nr | head -n 1 | sed 's/ [^ ]*$//'` + if [ -z "$prio" ]; then echo "update-alternatives: removing $link as no more alternatives exist for it" rm $ad/$name if [ -L $link ]; then @@ -107,11 +105,21 @@ find_best_alt() { return 0 fi + ## Find last line with highest priority. + path=`grep "${prio}$" $ad/$name | tail -n 1 | sed 's/ [^ ]*$//'` + if [ ! -e $link -o -L $link ]; then local link_dir=`dirname $link` if [ ! -d $link_dir ]; then mkdir -p $link_dir fi + if [ -h $link -a -d $link ]; then + # If $link exists and the target is a directory, + # 'ln -sf $path $link' doesn't replace the link to + # that directory, it creates new link inside. + echo "update-alternatives: Removing $link". + rm -f $link + fi ln -sf $path $link echo "update-alternatives: Linking $link to $path" else -- 2.25.1