commit:     a42e9e779795d1a4eff1a48ba14e70f03a64b98e
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Fri Mar 29 02:47:43 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Fri Mar 29 02:51:22 2019 +0000
URL:        https://gitweb.gentoo.org/proj/genkernel.git/commit/?id=a42e9e77

Add new function expand_file() to allow file path expansion

Relies on Python os.path.expanduser and realpath from coreutils.

Bug: https://bugs.gentoo.org/412321
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 gen_funcs.sh | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/gen_funcs.sh b/gen_funcs.sh
index 95c8f30..ba45b02 100755
--- a/gen_funcs.sh
+++ b/gen_funcs.sh
@@ -538,6 +538,25 @@ check_distfiles() {
        done
 }
 
+expand_file() {
+       [[ "$#" -lt '1' ]] &&
+               echo ''
+
+       local file="${1}"
+       local expanded_file=
+
+       expanded_file=$(python -c "import os; 
print(os.path.expanduser('${file}'))" 2>/dev/null)
+       if [ -z "${expanded_file}" ]
+       then
+               # if Python failed for some reason, just reset
+               expanded_file=${file}
+       fi
+
+       expanded_file=$(realpath -q "${expanded_file}" 2>/dev/null)
+
+       echo "${expanded_file}"
+}
+
 find_kernel_binary() {
        local kernel_binary=$*
        local curdir=$(pwd)

Reply via email to