posix_realpath: if dir does not exist also append to current dir

This matches realpath behavior.
This commit is contained in:
Julian Ospald 2019-04-18 11:37:42 +08:00
parent 6e1ee078cc
commit 17aafe3439
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28

4
ghcup
View File

@ -1127,7 +1127,7 @@ get_distro_alias() {
# and
# https://stackoverflow.com/a/246128
#
# If the file does not exist, just prints the argument unchanged.
# If the file does not exist, just prints it appended to the current directory.
# @STDOUT: realpath of the given file
posix_realpath() {
[ -z "$1" ] && die "Internal error: no argument given to posix_realpath"
@ -1151,8 +1151,6 @@ posix_realpath() {
# TODO: better distinguish between "does not exist" and "permission denied"
if [ -z "${mydir}" ] ; then
(>&2 echo "${1}: Permission denied")
elif [ ! -e "$1" ] ; then
echo "${mysource}"
else
echo "${mydir%/}/$(basename "${mysource}")"
fi