* [gentoo-portage-dev] [PATCH] use `readlink -f` if it works
@ 2012-09-24 0:28 Mike Frysinger
2012-09-24 1:32 ` Zac Medico
0 siblings, 1 reply; 2+ messages in thread
From: Mike Frysinger @ 2012-09-24 0:28 UTC (permalink / raw
To: gentoo-portage-dev
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>
---
bin/misc-functions.sh | 13 +++++++++++++
1 file changed, 13 insertions(+)
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
--
1.7.12
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [gentoo-portage-dev] [PATCH] use `readlink -f` if it works
2012-09-24 0:28 [gentoo-portage-dev] [PATCH] use `readlink -f` if it works Mike Frysinger
@ 2012-09-24 1:32 ` Zac Medico
0 siblings, 0 replies; 2+ messages in thread
From: Zac Medico @ 2012-09-24 1:32 UTC (permalink / raw
To: gentoo-portage-dev
On 09/23/2012 05:28 PM, Mike Frysinger wrote:
> Rather than always re-implementing `readlink -f` in shell, probe the host
> tool first to see if it works.
Looks good to me.
--
Thanks,
Zac
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2012-09-24 3:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-09-24 0:28 [gentoo-portage-dev] [PATCH] use `readlink -f` if it works Mike Frysinger
2012-09-24 1:32 ` Zac Medico
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox