From: Jean Delvare Subject: setup: Introduce function normalize_path Upstream: Committed (1e8e4ff9b8027235d0577369719c0c58ba460cf8) 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#*/}"