]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
convert_abs_rel() fixups
authorMichal Soltys <soltys@ziu.info>
Fri, 7 Oct 2011 20:23:49 +0000 (22:23 +0200)
committerHarald Hoyer <harald@redhat.com>
Mon, 10 Oct 2011 09:54:25 +0000 (11:54 +0200)
- 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>
dracut-functions

index c4f7f615814ba6420ba5396b3cbabc52b8e7cb3b..12dfa70c8d0b9d438b2c378e8457496c3d665853 100755 (executable)
@@ -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[@]}