diff options
author | Mike Frysinger <vapier@gentoo.org> | 2012-09-23 20:16:54 -0400 |
---|---|---|
committer | Mike Frysinger <vapier@gentoo.org> | 2012-09-23 20:16:54 -0400 |
commit | ca46b021359ffa13a808f99dd635a6958b369be5 (patch) | |
tree | 1ac6c674401d35e5cf3b60b35a359c53f2d69126 | |
parent | a8b9e099d08e72c10046639a15c3c7c02045c4da (diff) | |
download | portage-ca46b021359ffa13a808f99dd635a6958b369be5.tar.gz portage-ca46b021359ffa13a808f99dd635a6958b369be5.tar.bz2 portage-ca46b021359ffa13a808f99dd635a6958b369be5.zip |
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 <vapier@gentoo.org>
-rwxr-xr-x | bin/misc-functions.sh | 13 |
1 files changed, 13 insertions, 0 deletions
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 |