Browse Source

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>
master
Michal Soltys 13 years ago committed by Harald Hoyer
parent
commit
c44e3cb4e5
  1. 22
      dracut-functions

22
dracut-functions

@ -83,31 +83,29 @@ print_vars() { @@ -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[@]}

Loading…
Cancel
Save