From 8463281f6a6daec64a976693447c240f0d669f08 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Sun, 13 Jan 2019 15:11:40 -0800 Subject: misc-functions.sh: restore canonicalize func (bug 675284) The canonicalize function is required by install-qa-check.d/05prefix. Fixes: aa0a94198794 ("ecompress: Replace with implementation from portage[mgorny]") Bug: https://bugs.gentoo.org/670484 Signed-off-by: Zac Medico --- bin/misc-functions.sh | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'bin/misc-functions.sh') diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh index 5de26b44d..4f8a4112d 100755 --- a/bin/misc-functions.sh +++ b/bin/misc-functions.sh @@ -43,6 +43,40 @@ install_symlink_html_docs() { fi } +# 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 +} + install_qa_check() { local d f i qa_var x paths qa_checks=() checks_run=() if ! ___eapi_has_prefix_variables; then -- cgit v1.2.3-65-gdbad