Browse Source

convert_abs_rel() fixups

- IFS was not preserved, and modified value could leak to outside functions

- the '.' relative path should be returned for arguments such as /x/y/z
  /x/y - but not for $1 == $2 ones

- $1 == $2 is self-looping link, so it returns final component of its
  name

Signed-off-by: Michal Soltys <soltys@ziu.info>
master
Michal Soltys 13 years ago committed by Harald Hoyer
parent
commit
c1609dd497
  1. 18
      dracut-functions

18
dracut-functions

@ -91,20 +91,24 @@ normalize_path() { @@ -91,20 +91,24 @@ normalize_path() {
}

convert_abs_rel() {
local __current __absolute __abssize __cursize __i __level __newpath
local __current __absolute __abssize __cursize __newpath="" __oldifs
local -i __i __level=0
# PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';

if [[ "$1" == "$2" ]]
then
echo "."
return
fi
# corner case #1 - self looping link
[[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }

# corner case #2 - own dir link
[[ "${1%/*}" == "$2" ]] && { echo "."; return; }

__current=$(normalize_path "$1")
__absolute=$(normalize_path "$2")
IFS="/"

__oldifs="$IFS"
IFS="/"
__current=($__current)
__absolute=($__absolute)
IFS="$__oldifs"

__abssize=${#__absolute[@]}
__cursize=${#__current[@]}

Loading…
Cancel
Save