commit:     6192f2c0efcbd3633321929a5d2863ec1a87610c
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Sun Dec 23 19:54:27 2018 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Sun Dec 23 19:54:27 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=6192f2c0

bin/misc-functions.sh: restore canonicalize function

aa0a94198794f8ee8eedad26251b02f7b01dce17 removed this function without
really mentioning it.  In Prefix it's used for QA checks.

Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org>

 bin/misc-functions.sh | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)

diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh
index 0590a2862..692becaf6 100755
--- a/bin/misc-functions.sh
+++ b/bin/misc-functions.sh
@@ -47,6 +47,42 @@ install_symlink_html_docs() {
        fi
 }
 
+# PREFIX LOCAL: we need this on some platforms
+# 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
+                       f=${f%/}
+               done
+               b=${f##*/}
+               cd "${f%"${b}"}" 2>/dev/null || break
+               if [[ ! -L ${b} ]]; then
+                       f=$(pwd -P)
+                       echo "${f%/}/${b}"
+                       cd "${wd}"
+                       return 0
+               fi
+               f=$(readlink "${b}")
+       done
+       cd "${wd}"
+       return 1
+}
+# END PREFIX LOCAL
+
 install_qa_check() {
        local d f i qa_var x paths qa_checks=() checks_run=()
        if ! ___eapi_has_prefix_variables; then

Reply via email to