From c1609dd497bb8f8f083a258ff2f7702385eb940b Mon Sep 17 00:00:00 2001 From: Michal Soltys Date: Fri, 7 Oct 2011 22:23:49 +0200 Subject: [PATCH] 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 --- dracut-functions | 18 +++++++++++------- 1 files changed, 11 insertions(+), 7 deletions(-) diff --git a/dracut-functions b/dracut-functions index c4f7f61..12dfa70 100755 --- a/dracut-functions +++ b/dracut-functions @@ -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[@]}