diff --git a/scripts/libmakepkg/util/util.sh.in b/scripts/libmakepkg/util/util.sh.in index e1ca5cb7..1dfe6da9 100644 --- a/scripts/libmakepkg/util/util.sh.in +++ b/scripts/libmakepkg/util/util.sh.in @@ -49,20 +49,6 @@ is_array() { return $ret } -# Canonicalize a directory path if it exists -canonicalize_path() { - local path="$1"; - - if [[ -d $path ]]; then - ( - cd_safe "$path" - pwd -P - ) - else - printf "%s\n" "$path" - fi -} - dir_is_empty() { ( shopt -s dotglob nullglob @@ -79,10 +65,10 @@ cd_safe() { fi } -# Try to create directory if one does not yet exist. Fails if the directory -# exists but has no write permissions, or if there is an existing file with -# the same name. -ensure_writable_dir() { +# Try to create directory if one does not yet exist, and prints the +# canonical path to the directory. Fails if the directory exists but has no +# write permissions, or if there is an existing file with the same name. +canonicalize_and_ensure_writable_dir() { local dirtype="$1" dirpath="$2" if ! mkdir -p "$dirpath" 2>/dev/null; then @@ -92,6 +78,11 @@ ensure_writable_dir() { error "$(gettext "You do not have write permission for the directory \$%s (%s).")" "$dirtype" "$dirpath" return 1 fi - - return 0 + ( + if ! cd "$dirpath"; then + error "$(gettext "Could not canonicalize the directory \$%s (%s).")" "$dirtype" "$dirpath" + return 1 + fi + pwd -P + ) } diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in index 8ee0f5c5..62c2db80 100644 --- a/scripts/makepkg.sh.in +++ b/scripts/makepkg.sh.in @@ -1353,9 +1353,9 @@ if (( ${#extra_environment[*]} )); then export "${extra_environment[@]}" fi -# canonicalize paths and provide defaults if anything is still undefined +# provide defaults if anything is still undefined for var in PKGDEST SRCDEST SRCPKGDEST LOGDEST BUILDDIR; do - printf -v "$var" "$(canonicalize_path "${!var:-$startdir}")" + printf -v "$var" "${!var:-$startdir}" done unset var PACKAGER=${PACKAGER:-"Unknown Packager"} @@ -1378,23 +1378,23 @@ lint_config || exit $E_CONFIG_ERROR # check that all settings directories are user-writable -if ! ensure_writable_dir "BUILDDIR" "$BUILDDIR"; then +if ! BUILDDIR=$(canonicalize_and_ensure_writable_dir "BUILDDIR" "$BUILDDIR"); then plain "$(gettext "Aborting...")" exit $E_FS_PERMISSIONS fi -if (( ! (NOBUILD || GENINTEG) )) && ! ensure_writable_dir "PKGDEST" "$PKGDEST"; then +if (( ! (NOBUILD || GENINTEG) )) && ! PKGDEST=$(canonicalize_and_ensure_writable_dir "PKGDEST" "$PKGDEST"); then plain "$(gettext "Aborting...")" exit $E_FS_PERMISSIONS fi -if ! ensure_writable_dir "SRCDEST" "$SRCDEST" ; then +if ! SRCDEST=$(canonicalize_and_ensure_writable_dir "SRCDEST" "$SRCDEST"); then plain "$(gettext "Aborting...")" exit $E_FS_PERMISSIONS fi if (( SOURCEONLY )); then - if ! ensure_writable_dir "SRCPKGDEST" "$SRCPKGDEST"; then + if ! SRCPKGDEST=$(canonicalize_and_ensure_writable_dir "SRCPKGDEST" "$SRCPKGDEST"); then plain "$(gettext "Aborting...")" exit $E_FS_PERMISSIONS fi @@ -1404,7 +1404,7 @@ if (( SOURCEONLY )); then IGNOREARCH=1 fi -if (( LOGGING )) && ! ensure_writable_dir "LOGDEST" "$LOGDEST"; then +if (( LOGGING )) && ! LOGDEST=$(canonicalize_and_ensure_writable_dir "LOGDEST" "$LOGDEST"); then plain "$(gettext "Aborting...")" exit $E_FS_PERMISSIONS fi