[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Quilt-dev] [PATCH 1/2] setup: Introduce function normalize_path
From: |
Jean Delvare |
Subject: |
[Quilt-dev] [PATCH 1/2] setup: Introduce function normalize_path |
Date: |
Wed, 29 Oct 2014 15:33:41 +0100 |
Move the path normalization code to a separate function, to avoid
redundancy and make the code more readable.
---
quilt/setup.in | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
--- a/quilt/setup.in
+++ b/quilt/setup.in
@@ -71,6 +71,15 @@ check_for_existing_files()
return $status
}
+# Resolve ".." in path and clean up double slashes
+normalize_path()
+{
+ echo "$1" | sed -r -e 's://:/:g' \
+ -e ':again' \
+ -e 's:/[^/]+/\.\.(/|$):\1:g' \
+ -e 'tagain'
+}
+
create_symlink()
{
local target=$1 link=$2 up
@@ -80,16 +89,8 @@ create_symlink()
return
fi
- set -- "$(echo "$PWD/$target" | \
- sed -r -e 's://:/:g' \
- -e ':again' \
- -e 's:/[^/]+/\.\.(/|$):\1:g' \
- -e 'tagain')" \
- "$(echo "$PWD/$link" | \
- sed -r -e 's://:/:g' \
- -e ':again' \
- -e 's:/[^/]+/\.\.(/|$):\1:g' \
- -e 'tagain')"
+ set -- "$(normalize_path "$PWD/$target")" \
+ "$(normalize_path "$PWD/$link")"
while [ "${1%%/*}" = "${2%%/*}" ]
do
set -- "${1#*/}" "${2#*/}"
--
Jean Delvare
SUSE L3 Support
- [Quilt-dev] [PATCH 1/2] setup: Introduce function normalize_path,
Jean Delvare <=