[pacman-dev] [PATCH] makepkg: canonicalize paths from environmental variables

Allan McRae allan at archlinux.org
Mon Oct 4 01:01:50 EDT 2010


This prevents circular symlinks and weird final package locations
when using commands like  'PKGDEST="." makepkg'.

Fixes FS#20922.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 scripts/makepkg.sh.in |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/scripts/makepkg.sh.in b/scripts/makepkg.sh.in
index 9bcd446..ccf4213 100644
--- a/scripts/makepkg.sh.in
+++ b/scripts/makepkg.sh.in
@@ -1410,6 +1410,19 @@ run_split_packaging() {
 	done
 }
 
+# Canonicalize a path if it exists
+canonicalize_path() {
+	local path=$1;
+
+	if [[ -d $path ]]; then
+		cd $path
+		path=$(pwd)
+		cd - &>/dev/null
+	fi
+
+	echo $path
+}
+
 # getopt like parser
 parse_options() {
 	local short_options=$1; shift;
@@ -1615,10 +1628,10 @@ while true; do
 	shift
 done
 
-#preserve environment variables
-_PKGDEST=${PKGDEST}
-_SRCDEST=${SRCDEST}
-_SRCPKGDEST=${SRCPKGDEST}
+# preserve environment variables and canonicalize path
+[[ -n ${PKGDEST} ]] && _PKGDEST=$(canonicalize_path ${PKGDEST})
+[[ -n ${SRCDEST} ]] && _SRCDEST=$(canonicalize_path ${SRCDEST})
+[[ -n ${SRCPKGDEST} ]] && _SRCPKGDEST=$(canonicalize_path ${SRCPKGDEST})
 
 # default config is makepkg.conf
 MAKEPKG_CONF=${MAKEPKG_CONF:-$confdir/makepkg.conf}
-- 
1.7.3.1




More information about the pacman-dev mailing list