From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id D49D3138010 for ; Mon, 24 Sep 2012 03:47:56 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 710C621C0B7; Mon, 24 Sep 2012 03:47:33 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 445A521C0B7 for ; Mon, 24 Sep 2012 03:47:33 +0000 (UTC) Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id AE15B33CBA9 for ; Mon, 24 Sep 2012 03:47:32 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 652CDE5444 for ; Mon, 24 Sep 2012 03:47:31 +0000 (UTC) From: "Mike Frysinger" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Mike Frysinger" Message-ID: <1348445814.ca46b021359ffa13a808f99dd635a6958b369be5.vapier@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/misc-functions.sh X-VCS-Directories: bin/ X-VCS-Committer: vapier X-VCS-Committer-Name: Mike Frysinger X-VCS-Revision: ca46b021359ffa13a808f99dd635a6958b369be5 X-VCS-Branch: master Date: Mon, 24 Sep 2012 03:47:31 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 245a84f3-1381-4a83-8306-f98fd85c1862 X-Archives-Hash: 55da5d4140500e2337d0f08c46a1cec8 commit: ca46b021359ffa13a808f99dd635a6958b369be5 Author: Mike Frysinger gentoo org> AuthorDate: Mon Sep 24 00:16:54 2012 +0000 Commit: Mike Frysinger gentoo org> CommitDate: Mon Sep 24 00:16:54 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=ca46b021 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 gentoo.org> --- 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 ac08bd9..c8b7cc8 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