  
  		for dep in $build_only_dl_g; do
 +			if [ -n "${use_pkgng}" ]; then
-+				[ `pkg query "%?r"` = "0" ] || temp_bodlg="$temp_bodlg $dep"
++				[ "`pkg query "%?r" $dep`" = "0" ] || temp_bodlg="$temp_bodlg $dep"
 +				continue
 +			fi
  			grep -q "@comment DEPORIGIN:${dep#$pd/}$" $pdb/*/+CONTENTS ||

+	if [ -z "$usr_pkgng" ]; then
+		pkglist="pkg_info -q -L"
+	else
+		pkglist="pkg info -q -l -a"
+	fi
+	for file in `$pkglist $new_port`; do
 		[ -f "${LOCALBASE_COMPAT}/${file##*/}" ] &&

+		if [ -z "$usr_pkgng" ]; then
+			pkglist="pkg_info -q -L"
+		else
+			pkglist="pkg info -q -l"
+		fi
+		for file in `$pkglist $UPGRADE_PORT |
 		    sort - $ldconfig_out | uniq -d`; do
