Blob Blame History Raw
From c44e3cb4e5ace39247c0a6619668add2d1dc92e8 Mon Sep 17 00:00:00 2001
From: Michal Soltys <soltys@ziu.info>
Date: Sat, 8 Oct 2011 00:20:50 +0200
Subject: [PATCH] dracut-functions: conv/normalize minor corrections

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 |   22 ++++++++++------------
 1 files changed, 10 insertions(+), 12 deletions(-)

diff --git a/dracut-functions b/dracut-functions
index 12dfa70..ce593c9 100755
--- a/dracut-functions
+++ b/dracut-functions
@@ -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[@]}