dracut-functions: conv/normalize minor corrections
authorMichal Soltys <soltys@ziu.info>
Fri, 7 Oct 2011 22:20:50 +0000 (00:20 +0200)
committerHarald Hoyer <harald@redhat.com>
Mon, 10 Oct 2011 09:54:26 +0000 (11:54 +0200)
mostly with reference to earlier commit:

- bash doesn't need unsetting locals
- make normalize_path() a bit faster, also make sure we remove all
  trailing slashes
- normalize paths before tests

Signed-off-by: Michal Soltys <soltys@ziu.info>
dracut-functions

index 12dfa70..ce593c9 100755 (executable)
@@ -83,31 +83,29 @@ print_vars() {
 }
 
 normalize_path() {
-    p=$1
-    while [[ ${p#*//*} != $p ]]; do
-        p=${p/\/\///}
-    done
-    echo $p
+    shopt -q -s extglob
+    set -- "${1//+(\/)//}"
+    shopt -q -u extglob
+    echo "${1%/}"
 }
 
 convert_abs_rel() {
-    local __current __absolute __abssize __cursize __newpath="" __oldifs
-    local -i __i __level=0
+    local __current __absolute __abssize __cursize __newpath __oldifs
+    local -i __i __level
 #    PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
 
+    set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
+
     # 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")
-
     __oldifs="$IFS"
     IFS="/"
-    __current=($__current)
-    __absolute=($__absolute)
+    __current=($1)
+    __absolute=($2)
     IFS="$__oldifs"
 
     __abssize=${#__absolute[@]}