Index: bin/ebuild.sh
===================================================================
--- bin/ebuild.sh	(revision 2660)
+++ bin/ebuild.sh	(working copy)
@@ -1185,78 +1185,29 @@
 		unset INSTALLTOD
 	fi
 
-	# dumps perms to stdout.  if error, no perms dumped.
-	function stat_perms() {
-		local f
-		# only define do_stat if it hasn't been already
-		if ! type -p do_stat &> /dev/null; then
-			if ! type -p stat &>/dev/null; then
-				do_stat() {
-					# Generic version -- Octal result
-					python -c "import os,stat; print '%o' % os.stat('$1')[stat.ST_MODE]"
-				}
-			else
-				if [ "${USERLAND}" == "BSD" ] || [ "${USERLAND}" == "Darwin" ]; then
-					do_stat() {
-						# BSD version -- Octal result
-						$(type -p stat) -f '%p' "$1"
-					}
-				else
-					do_stat() {
-						# Linux version -- Hex result converted to Octal
-						f=$($(type -p stat) -c '%f' "$1") || return $?
-						printf '%o' "0x$f"
-					}
-				fi
-			fi
-		fi
+	local file="${T}/find-portage-log"
+	local count=$(find "${D}"/ -user portage | wc -l)
+	if [[ ${count} -gt 0 ]] ; then
+		ewarn "${count} files were installed with user portage!"
 
-		f=$(do_stat "$@") || return
-		f="${f:2:4}"
-		echo $f
-	}
-
-	local file s
-	local count=0
-	find "${D}/" -user  portage | while read file; do
-		count=$(( $count + 1 ))
-		if [ -L "${file}" ]; then
-			lchown ${PORTAGE_INST_UID} "${file}"
-		else
-			s=$(stat_perms "$file")
-			if [ -z "${s}" ]; then
-				ewarn "failed stat_perm'ing $file.  User intervention during install isn't wise..."
-				continue
-			fi
-			chown ${PORTAGE_INST_UID} "$file"
-			chmod "$s" "$file"
-		fi
-	done
-	if (( $count > 0 )); then
-		ewarn "$count files were installed with user portage!"
+		find "${D}"/ -xtype l -user portage -print0 > "${file}"
+		[[ -s ${file} ]] && xargs -a "${file}" -0 chown -h ${PORTAGE_INST_UID}
+		find "${D}"/ -user portage -print0 > "${file}"
+		[[ -s ${file} ]] && xargs -a "${file}" -0 chown ${PORTAGE_INST_UID}
+		rm -f "${file}"
 	fi
 
-	count=0
-	find "${D}/" -group portage | while read file; do
-		count=$(( $count + 1 ))
-		if [ -L "${file}" ]; then
-			lchgrp ${PORTAGE_INST_GID} "${file}"
-		else
-			s=$(stat_perms "$file")
-			if [ -z "${s}" ]; then
-				echo "failed stat_perm'ing '$file' . User intervention during install isn't wise..."
-				continue
-			fi
-			chgrp ${PORTAGE_INST_GID} "$file"
-			chmod "$s" "$file"
-		fi
-	done
-	if (( $count > 0 )); then
-		ewarn "$count files were installed with group portage!"
+	count=$(find "${D}"/ -group portage | wc -l)
+	if [[ ${count} -gt 0 ]] ; then
+		ewarn "${count} files were installed with group portage!"
+
+		find "${D}"/ -xtype l -group portage -print0 > "${file}"
+		[[ -s ${file} ]] && xargs -a "${file}" -0 chgrp -h ${PORTAGE_INST_GID}
+		find "${D}"/ -group portage -print0 > "${file}"
+		[[ -s ${file} ]] && xargs -a "${file}" -0 chgrp ${PORTAGE_INST_GID}
+		rm -f "${file}"
 	fi
 
-	unset -f stat_perms
-
 	# Portage regenerates this on the installed system.
 	if [ -f "${D}/usr/share/info/dir.gz" ]; then
 		rm -f "${D}/usr/share/info/dir.gz"