|
Harald Hoyer |
55891e |
From c44e3cb4e5ace39247c0a6619668add2d1dc92e8 Mon Sep 17 00:00:00 2001
|
|
Harald Hoyer |
55891e |
From: Michal Soltys <soltys@ziu.info>
|
|
Harald Hoyer |
55891e |
Date: Sat, 8 Oct 2011 00:20:50 +0200
|
|
Harald Hoyer |
55891e |
Subject: [PATCH] dracut-functions: conv/normalize minor corrections
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
mostly with reference to earlier commit:
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
- bash doesn't need unsetting locals
|
|
Harald Hoyer |
55891e |
- make normalize_path() a bit faster, also make sure we remove all
|
|
Harald Hoyer |
55891e |
trailing slashes
|
|
Harald Hoyer |
55891e |
- normalize paths before tests
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
Signed-off-by: Michal Soltys <soltys@ziu.info>
|
|
Harald Hoyer |
55891e |
---
|
|
Harald Hoyer |
55891e |
dracut-functions | 22 ++++++++++------------
|
|
Harald Hoyer |
55891e |
1 files changed, 10 insertions(+), 12 deletions(-)
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
diff --git a/dracut-functions b/dracut-functions
|
|
Harald Hoyer |
55891e |
index 12dfa70..ce593c9 100755
|
|
Harald Hoyer |
55891e |
--- a/dracut-functions
|
|
Harald Hoyer |
55891e |
+++ b/dracut-functions
|
|
Harald Hoyer |
55891e |
@@ -83,31 +83,29 @@ print_vars() {
|
|
Harald Hoyer |
55891e |
}
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
normalize_path() {
|
|
Harald Hoyer |
55891e |
- p=$1
|
|
Harald Hoyer |
55891e |
- while [[ ${p#*//*} != $p ]]; do
|
|
Harald Hoyer |
55891e |
- p=${p/\/\///}
|
|
Harald Hoyer |
55891e |
- done
|
|
Harald Hoyer |
55891e |
- echo $p
|
|
Harald Hoyer |
55891e |
+ shopt -q -s extglob
|
|
Harald Hoyer |
55891e |
+ set -- "${1//+(\/)//}"
|
|
Harald Hoyer |
55891e |
+ shopt -q -u extglob
|
|
Harald Hoyer |
55891e |
+ echo "${1%/}"
|
|
Harald Hoyer |
55891e |
}
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
convert_abs_rel() {
|
|
Harald Hoyer |
55891e |
- local __current __absolute __abssize __cursize __newpath="" __oldifs
|
|
Harald Hoyer |
55891e |
- local -i __i __level=0
|
|
Harald Hoyer |
55891e |
+ local __current __absolute __abssize __cursize __newpath __oldifs
|
|
Harald Hoyer |
55891e |
+ local -i __i __level
|
|
Harald Hoyer |
55891e |
# PS4='${BASH_SOURCE}@${LINENO}(${FUNCNAME[0]}): ';
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
+ set -- "$(normalize_path "$1")" "$(normalize_path "$2")"
|
|
Harald Hoyer |
55891e |
+
|
|
Harald Hoyer |
55891e |
# corner case #1 - self looping link
|
|
Harald Hoyer |
55891e |
[[ "$1" == "$2" ]] && { echo "${1##*/}"; return; }
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
# corner case #2 - own dir link
|
|
Harald Hoyer |
55891e |
[[ "${1%/*}" == "$2" ]] && { echo "."; return; }
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
- __current=$(normalize_path "$1")
|
|
Harald Hoyer |
55891e |
- __absolute=$(normalize_path "$2")
|
|
Harald Hoyer |
55891e |
-
|
|
Harald Hoyer |
55891e |
__oldifs="$IFS"
|
|
Harald Hoyer |
55891e |
IFS="/"
|
|
Harald Hoyer |
55891e |
- __current=($__current)
|
|
Harald Hoyer |
55891e |
- __absolute=($__absolute)
|
|
Harald Hoyer |
55891e |
+ __current=($1)
|
|
Harald Hoyer |
55891e |
+ __absolute=($2)
|
|
Harald Hoyer |
55891e |
IFS="$__oldifs"
|
|
Harald Hoyer |
55891e |
|
|
Harald Hoyer |
55891e |
__abssize=${#__absolute[@]}
|