update-alternatives: add support for link renames

During package upgrades, the link location might change. For example:

Package A: 'update-alternatives --install /bin/app app /some/real/path 100'
Package B: 'update-alternatives --install /sbin/app app /some/other/path 100'

Opkg disallows a link change and throws an error. Debian does allow the
operation, changing the link to the new location. Add support to follow
the debian update-alternatives behavior.

bugzilla #8344

Signed-off-by: Alejandro del Castillo <alejandro.delcastillo@ni.com>
This commit is contained in:
Alejandro del Castillo
2018-01-23 12:00:22 -06:00
parent f2e63deda2
commit fcb2633900

View File

@@ -54,8 +54,11 @@ register_alt() {
if [ -e "$ad/$name" ]; then
local olink=`head -n 1 $ad/$name`
if [ "$link" != "$olink" ]; then
echo "update-alternatives: Error: cannot register alternative $name to $link since it is already registered to $olink" >&2
return 1
echo "update-alternatives: renaming $name link from $olink to $link"
local link_str=`echo $link | protect_slashes`
sed -e "1s/.*/$link_str/" $ad/$name > $ad/$name.new
mv $ad/$name.new $ad/$name
mv $olink $link
fi
else
echo "$link" > "$ad/$name"