From: Mike Frysinger Date: Mon, 24 Sep 2012 00:16:54 +0000 (-0400) Subject: use `readlink -f` if it works X-Git-Tag: v2.2.0_alpha133~32 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=ca46b021359ffa13a808f99dd635a6958b369be5;p=portage.git use `readlink -f` if it works Rather than always re-implementing `readlink -f` in shell, probe the host tool first to see if it works. Signed-off-by: Mike Frysinger --- diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh index ac08bd948..c8b7cc8b0 100755 --- a/bin/misc-functions.sh +++ b/bin/misc-functions.sh @@ -43,7 +43,20 @@ install_symlink_html_docs() { } # replacement for "readlink -f" or "realpath" +READLINK_F_WORKS="" canonicalize() { + if [[ -z ${READLINK_F_WORKS} ]] ; then + if [[ $(readlink -f -- /../ 2>/dev/null) == "/" ]] ; then + READLINK_F_WORKS=true + else + READLINK_F_WORKS=false + fi + fi + if ${READLINK_F_WORKS} ; then + readlink -f -- "$@" + return + fi + local f=$1 b n=10 wd=$(pwd) while (( n-- > 0 )); do while [[ ${f: -1} = / && ${#f} -gt 1 ]]; do