Gentoo Archives: gentoo-portage-dev

From: Mike Frysinger <vapier@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] use `readlink -f` if it works
Date: Mon, 24 Sep 2012 03:16:25
Message-Id: 1348446531-18138-1-git-send-email-vapier@gentoo.org
1 Rather than always re-implementing `readlink -f` in shell, probe the host
2 tool first to see if it works.
3
4 Signed-off-by: Mike Frysinger <vapier@g.o>
5 ---
6 bin/misc-functions.sh | 13 +++++++++++++
7 1 file changed, 13 insertions(+)
8
9 diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
10 index ac08bd9..c8b7cc8 100755
11 --- a/bin/misc-functions.sh
12 +++ b/bin/misc-functions.sh
13 @@ -43,7 +43,20 @@ install_symlink_html_docs() {
14 }
15
16 # replacement for "readlink -f" or "realpath"
17 +READLINK_F_WORKS=""
18 canonicalize() {
19 + if [[ -z ${READLINK_F_WORKS} ]] ; then
20 + if [[ $(readlink -f -- /../ 2>/dev/null) == "/" ]] ; then
21 + READLINK_F_WORKS=true
22 + else
23 + READLINK_F_WORKS=false
24 + fi
25 + fi
26 + if ${READLINK_F_WORKS} ; then
27 + readlink -f -- "$@"
28 + return
29 + fi
30 +
31 local f=$1 b n=10 wd=$(pwd)
32 while (( n-- > 0 )); do
33 while [[ ${f: -1} = / && ${#f} -gt 1 ]]; do
34 --
35 1.7.12

Replies

Subject Author
Re: [gentoo-portage-dev] [PATCH] use `readlink -f` if it works Zac Medico <zmedico@g.o>