Subject: Changes to reference count directories, 2nd round
To: None <tech-pkg@NetBSD.org>
From: Johnny C. Lam <jlam@buildlink.org>
List: tech-pkg
Date: 01/26/2005 23:29:51
--6TrnltStXW4iwmi0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline

I've attached my latest patches to implement directory reference
counting.  Please comment by Friday, January 29 09:00:00 UTC.

	Thanks,

	-- Johnny Lam <jlam@NetBSD.org>

--6TrnltStXW4iwmi0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename=COMMIT

  Summary of changes from 1st round
  =================================

* The reference counts database is now stored in ${PKG_DBDIR}/.refcount.

* We now properly note directories as pre-existing even if they are not
  empty.

* The implementation of CHECK-ADD and CHECK-REMOVE have been simplified
  to not require START/END tags to delimit the lines containing data.
  Now, every line that begins with "# DIRS: " is considered to be data.

* We now unpack the +DIRS script before all other PRE-INSTALL stages
  are run by using the new INSTALL_UNPACK_TMPL variable.  The +INSTALL
  and +DEINSTALL scripts now simply check for the existence of the
  +DIRS script and invoke it in the right places.


  Commit message
  ==============

Use reference counts to properly account for the creation and removal
of directories needed for the proper functioning of each package.

The +INSTALL script unpacks a +DIRS script that adds and removes
directories.  The +DIRS script entirely encapsulates the directory
creation and removal, and completely replaces the code in the
mk/install/install and mk/install/deinstall templates that handled
{MAKE,OWN}_DIRS and {MAKE,OWN}_DIRS_PERMS.

The +DIRS script is meant to be executed from within the package
meta-data directory, e.g.  /var/db/pkg/<pkgname>.  It's usage is:

	./+DIRS ADD|REMOVE|CHECK-ADD|CHECK-REMOVE

The ADD and REMOVE actions cause the necessary directories to be added
or removed from the system.  The CHECK-ADD and CHECK-REMOVE actions
print out informative messages prompting the user to either create or
remove some necessary directories.

The behaviour of "ADD" is such that if the directory already exists
on the system and is not already ref-counted, then that directory is
marked as "pre-existing".  On "REMOVE", pre-existing directories are
left untouched on the filesystem.

At any time, the root user can sanity-check the directories needed by
packages by invoking all of the +DIRS scripts with the "CHECK-ADD"
action.  If there are missing directories, then invoking all of the
+DIRS scripts with the "ADD" action will ensure that any missing
directories are created.

The reference counts database is stored in ${PKG_DBDIR}/.refcount.
If the reference counts database is removed, then invoking all of the
+DIRS scripts with the "ADD" action will reconstruct the database;
however, directories may be marked as being pre-existing, so they
won't be removed at package de-installation (although a message will
be displayed informing the user that those directories can be removed).

--6TrnltStXW4iwmi0
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="refcount.diff"

Index: bsd.pkg.install.mk
===================================================================
RCS file: /cvsroot/pkgsrc/mk/bsd.pkg.install.mk,v
retrieving revision 1.72
diff -u -r1.72 bsd.pkg.install.mk
--- bsd.pkg.install.mk	26 Jan 2005 23:15:03 -0000	1.72
+++ bsd.pkg.install.mk	26 Jan 2005 23:18:33 -0000
@@ -208,10 +208,62 @@
 MAKE_DIRS_PERMS?=	# empty
 OWN_DIRS?=		# empty
 OWN_DIRS_PERMS?=	# empty
-FILES_SUBST+=		MAKE_DIRS=${MAKE_DIRS:Q}
-FILES_SUBST+=		MAKE_DIRS_PERMS=${MAKE_DIRS_PERMS:Q}
-FILES_SUBST+=		OWN_DIRS=${OWN_DIRS:Q}
-FILES_SUBST+=		OWN_DIRS_PERMS=${OWN_DIRS_PERMS:Q}
+
+_PKG_REFCOUNT_DBDIR=	${PKG_DBDIR}/.refcount
+FILES_SUBST+=		PKG_REFCOUNT_DBDIR=${_PKG_REFCOUNT_DBDIR:Q}
+
+INSTALL_DIRS_FILE=	${WRKDIR}/.install-dirs
+INSTALL_UNPACK_TMPL+=	${INSTALL_DIRS_FILE}
+
+${INSTALL_DIRS_FILE}: ../../mk/install/dirs
+	${_PKG_SILENT}${_PKG_DEBUG}{					\
+	${ECHO} "# start of install-dirs";				\
+	${ECHO} "#";							\
+	${ECHO} "# Generate a +DIRS script that reference counts directories"; \
+	${ECHO} "# that are required for the proper functioning of the"; \
+	${ECHO} "# package.";						\
+	${ECHO} "#";							\
+	${ECHO} "case \$${STAGE} in";					\
+	${ECHO} "PRE-INSTALL)";						\
+	${ECHO} "	\$${CAT} > ./+DIRS << 'EOF_DIRS'";		\
+	${SED} ${FILES_SUBST_SED} ../../mk/install/dirs;		\
+	${ECHO} "";							\
+	case "${CONF_FILES}${CONF_FILES_PERMS}${SUPPORT_FILES}${SUPPORT_FILES_PERMS}" in \
+	"")	;;							\
+	*)	${ECHO} "# DIRS: ${PKG_SYSCONFDIR} m" ;;		\
+	esac;								\
+	case "${RCD_SCRIPTS}" in					\
+	"")	;;							\
+	*)	${ECHO} "# DIRS: ${RCD_SCRIPTS_DIR} m" ;;		\
+	esac;								\
+	eval set -- ${MAKE_DIRS} ;					\
+	while ${TEST} $$# -gt 0; do					\
+		dir="$$1"; shift;					\
+		${ECHO} "# DIRS: $$dir m";				\
+	done;								\
+	eval set -- ${OWN_DIRS} ;					\
+	while ${TEST} $$# -gt 0; do					\
+		dir="$$1"; shift;					\
+		${ECHO} "# DIRS: $$dir mo";				\
+	done;								\
+	eval set -- ${MAKE_DIRS_PERMS} ;				\
+	while ${TEST} $$# -gt 0; do					\
+		dir="$$1"; owner="$$2"; group="$$3"; mode="$$4";	\
+		shift; shift; shift; shift;				\
+		${ECHO} "# DIRS: $$dir m $$owner $$group $$mode";	\
+	done;								\
+	eval set -- ${OWN_DIRS_PERMS} ;					\
+	while ${TEST} $$# -gt 0; do					\
+		dir="$$1"; owner="$$2"; group="$$3"; mode="$$4";	\
+		shift; shift; shift; shift;				\
+		${ECHO} "# DIRS: $$dir mo $$owner $$group $$mode";	\
+	done;								\
+	${ECHO} "EOF_DIRS";						\
+	${ECHO} "	\$${CHMOD} +x ./+DIRS";				\
+	${ECHO} "	;;";						\
+	${ECHO} "esac";							\
+	} > ${.TARGET}.tmp;						\
+	${MV} -f ${.TARGET}.tmp ${.TARGET}
 
 # PKG_CREATE_USERGROUP indicates whether the INSTALL script should
 #	automatically add any needed users/groups to the system using
@@ -298,6 +350,7 @@
 FILES_SUBST_SED=	${FILES_SUBST:S/=/@!/:S/$/!g/:S/^/ -e s!@/}
 
 INSTALL_SCRIPTS_ENV=	PKG_PREFIX=${PREFIX}
+INSTALL_SCRIPTS_ENV+=	PKG_METADATA_DIR=${_PKG_DBDIR}/${PKGNAME}
 
 .PHONY: pre-install-script post-install-script
 
Index: install/deinstall
===================================================================
RCS file: /cvsroot/pkgsrc/mk/install/deinstall,v
retrieving revision 1.29
diff -u -r1.29 deinstall
--- install/deinstall	11 Oct 2004 22:04:19 -0000	1.29
+++ install/deinstall	26 Jan 2005 23:18:33 -0000
@@ -45,34 +45,6 @@
 	VIEW_FILES="${VIEW_FILES} \"${file}\""
 done
 
-eval set -- ${PKG_SYSCONFDIR} ${RCD_SCRIPTS_DIR} ${MAKE_DIRS}
-for dir; do
-	ALL_MAKE_DIRS="${ALL_MAKE_DIRS} \"${dir}\""
-done
-eval set -- ${MAKE_DIRS_PERMS}
-while [ $# -gt 0 ]; do
-	dir="$1"; owner="$2"; group="$3"; mode="$4"
-	shift; shift; shift; shift
-	ALL_MAKE_DIRS="${ALL_MAKE_DIRS} \"${dir}\""
-done
-eval set -- ${ALL_MAKE_DIRS} ${OWN_DIRS}
-for dir; do
-	ALL_DIRS="${ALL_DIRS} \"${dir}\""
-done
-eval set -- ${OWN_DIRS_PERMS}
-while [ $# -gt 0 ]; do
-	dir="$1"; owner="$2"; group="$3"; mode="$4"
-	shift; shift; shift; shift
-	ALL_DIRS="${ALL_DIRS} \"${dir}\""
-done
-ALL_DIRS=`
-	( eval set -- ${ALL_DIRS}
-	  for dir; do
-		${ECHO} "\"${dir}\""
-	  done
-	) | ${SORT} -r
-`
-
 case ${STAGE} in
 VIEW-DEINSTALL)
 	if [ "${_PKG_CONFIG}" = "YES" -a -n "${VIEW_FILES}" ]; then
@@ -140,51 +112,9 @@
 		${RMDIR} -p `${DIRNAME} ${PKG_SYSCONFDIR}` 2>/dev/null || ${TRUE}
 	fi
 
-	existing_dirs=''
-	eval set -- ${ALL_DIRS}
-	for dir; do
-        	if [ "${_PKG_CONFIG}" = "YES" ]; then
-			if [ -f "${dir}/.pkgsrc" ]; then
-				dirowner=`${HEAD} -1 "${dir}/.pkgsrc"`
-				if [ "${dirowner}" = "${PKGBASE}" ]; then
-					${RM} -f "${dir}/.pkgsrc"
-					${RMDIR} -p "${dir}" 2>/dev/null || ${TRUE}
-				fi
-			fi
-			is_make_dir=`					\
-				eval set -- ${ALL_MAKE_DIRS};		\
-				is_make_dir=0;				\
-				for make_dir; do			\
-					case "${make_dir}" in		\
-					${dir}) is_make_dir=1; break ;;	\
-					esac;				\
-				done;					\
-				${ECHO} ${is_make_dir}			\
-			`
-			if [ ${is_make_dir} -eq 0 -a -d "${dir}" ]; then
-				existing_dirs="${existing_dirs} \"${dir}\""
-			fi
-		else
-			case "${dir}" in
-			${PKG_PREFIX}/*)
-				${RMDIR} -p "${dir}" 2>/dev/null || ${TRUE}
-				;;
-			esac
-			case "${dir}" in
-			#
-			# Don't bother the admin about the following dirs
-			# if they still exist.
-			#
-			${PKG_SYSCONFBASE}|${RCD_SCRIPTS_DIR})
-				;;
-			*)	
-				if [ -d "${dir}" ]; then
-					existing_dirs="${existing_dirs} \"${dir}\""
-				fi
-				;;
-			esac
-		fi
-	done
+	case ${_PKG_CONFIG} in
+	YES)	${TEST} -x ./+DIRS && ./+DIRS REMOVE ${PKG_METADATA_DIR} ;;
+	esac
 
 	if [ -n "${ALL_USERS}" -o -n "${ALL_GROUPS}" -o			\
 	     -n "${modified_files}" -o -n "${existing_dirs}" ]; then
@@ -225,17 +155,6 @@
 				${ECHO} "	${file}"
 			done
 		fi
-		if [ -n "${existing_dirs}" ]; then
-			${CAT} << EOF
-
-  * the following directories:
-
-EOF
-			eval set -- ${existing_dirs}
-			for dir; do
-				${ECHO} "	${dir}"
-			done
-		fi
 		if [ -n "${RCD_SCRIPTS}" ]; then
 			${CAT} << EOF
 
@@ -246,6 +165,7 @@
 		${CAT} << EOF
 ===========================================================================
 EOF
+	${TEST} -x ./+DIRS && ./+DIRS CHECK-REMOVE
 	fi
 	;;
 esac
Index: install/dirs
===================================================================
RCS file: install/dirs
diff -N install/dirs
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ install/dirs	26 Jan 2005 23:18:33 -0000
@@ -0,0 +1,196 @@
+#!@SH@
+#
+# +DIRS - reference-counted directory management script
+#
+# Usage: ./+DIRS ADD|REMOVE [metadatadir]
+#        ./+DIRS CHECK-ADD|CHECK-REMOVE
+#
+# This script supports two actions, ADD and REMOVE, that will add or
+# remove the directories needed by the package associated with
+# <metadatadir>.  The CHECK-ADD action will check whether any directories
+# needed by the package are missing, and print an informative message
+# noting those directories.  The CHECK-REMOVE action will check whether
+# any directories needed by the package still exist, and print an
+# informative message noting those directories.
+#
+# Lines starting with "# DIRS: " are data read by this script that
+# names the directories that this package requires to exist to
+# function correctly, e.g.
+#
+#	# DIRS: /etc/foo m
+#	# DIRS: /var/log/foo/tmp mo foo-user foo-group 0700
+#
+# The second field in each DIRS entry is a set of flags with the following
+# meaning:
+#
+#	m	create (make) the directory when ADDing
+#	o	directory is owned by the package
+#
+CAT="@CAT@"
+CHGRP="@CHGRP@"
+CHMOD="@CHMOD@"
+CHOWN="@CHOWN@"
+ECHO="@ECHO@"
+GREP="@GREP@"
+MKDIR="@MKDIR@"
+MV="@MV@"
+PWD_CMD="@PWD_CMD@"
+RM="@RM@"
+RMDIR="@RMDIR@"
+SED="@SED@"
+SORT="@SORT@"
+TEST="@TEST@"
+TRUE="@TRUE@"
+
+SELF=$0
+ACTION=$1
+PKG_METADATA_DIR="${2-`${PWD_CMD}`}"
+PKG_REFCOUNT_DBDIR="@PKG_REFCOUNT_DBDIR@"
+: ${PKGNAME=${PKG_METADATA_DIR##*/}}
+
+case $ACTION in
+ADD)
+	${SED} -n "/^\# DIRS: /{s/^\# DIRS: //;p;}" ${SELF} | ${SORT} -u |
+	while read dir d_flags d_user d_group d_mode; do
+		case $dir in
+		""|[!/]*)	continue ;;
+		esac
+		case $d_flags in
+		*m*)	;;
+		*)	continue ;;
+		esac
+		shadow_dir="${PKG_REFCOUNT_DBDIR}$dir"
+		perms="$shadow_dir/+PERMISSIONS"
+		preexist="$shadow_dir/+PREEXISTING"
+		token="$shadow_dir/${PKGNAME}"
+		if ${TEST} ! -d "$shadow_dir"; then
+			${MKDIR} $shadow_dir
+			${TEST} -d "$dir" &&
+				${ECHO} "${PKGNAME}" > $preexist
+		fi
+		${MKDIR} $dir
+		if ${TEST} -f "$token" && \
+		   ${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then
+			:
+		else
+			${ECHO} "${PKG_METADATA_DIR}" >> $token
+		fi
+		case $d_user/$d_group/$d_mode in
+		[!/]*/[!/]*/[!/]*)
+			${ECHO} "$d_user $d_group $d_mode" > $perms
+			;;
+		esac
+		case $d_user/$d_group/$d_mode in
+		[!/]*/[!/]*/[!/]*)
+			${CHOWN} $d_user $dir
+			${CHGRP} $d_group $dir
+			${CHMOD} $d_mode $dir
+			;;
+		esac
+	done
+	;;
+
+REMOVE)
+	${SED} -n "/^\# DIRS: /{s/^\# DIRS: //;p;}" ${SELF} | ${SORT} -ru |
+	while read dir d_flags d_user d_group d_mode; do
+		case $dir in
+		""|[!/]*)	continue ;;
+		esac
+		case $d_flags in
+		*m*)	;;
+		*)	continue ;;
+		esac
+		shadow_dir="${PKG_REFCOUNT_DBDIR}$dir"
+		perms="$shadow_dir/+PERMISSIONS"
+		preexist="$shadow_dir/+PREEXISTING"
+		token="$shadow_dir/${PKGNAME}"
+		tokentmp="$token.tmp.$$"
+		if ${TEST} -f "$token" && \
+		   ${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then
+			${CAT} "$token" | ${GREP} -v "^${PKG_METADATA_DIR}$" > $tokentmp
+			case `${CAT} $tokentmp | ${SED} -n "$="` in
+			"")
+				${TEST} -f "$preexist" ||
+					{ ${RMDIR} -p $dir 2>/dev/null || ${TRUE}; }
+				${RM} -f $perms $preexist $token $token.tmp.*
+				${RMDIR} -p $shadow_dir 2>/dev/null || ${TRUE}
+				;;
+			*)
+				${MV} -f $tokentmp $token
+				;;
+			esac
+		fi
+	done
+	;;
+
+CHECK-ADD)
+	${SED} -n "/^\# DIRS: /{s/^\# DIRS: //;p;}" ${SELF} | ${SORT} -u |
+	{ while read dir d_flags d_user d_group d_mode; do
+		case $dir in
+		""|[!/]*)	continue ;;
+		*)		${TEST} -d "$dir" && continue ;;
+		esac
+		case $d_flags in
+		*m*)	;;
+		*)	continue ;;
+		esac
+		case "$printed_header" in
+		yes)	;;
+		*)	printed_header=yes
+			${ECHO} "==========================================================================="
+			${ECHO} "The following directories should be created for ${PKGNAME}:"
+			${ECHO} ""
+			;;
+		esac
+		case $d_user/$d_group/$d_mode in
+		[!/]*/[!/]*/[!/]*)
+			${ECHO} "	${dir} (o=${d_user}, g=${d_group}, m=${d_mode})"
+			;;
+		*)
+			${ECHO} "	${dir}"
+			;;
+		esac
+	done
+	case "$printed_header" in
+	yes)	${ECHO} ""
+		${ECHO} "==========================================================================="
+		;;
+	esac; }
+	;;
+
+CHECK-REMOVE)
+	${SED} -n "/^\# DIRS: /{s/^\# DIRS: //;p;}" ${SELF} | ${SORT} -ru |
+	{ while read dir d_flags d_user d_group d_mode; do
+		case $dir in
+		""|[!/]*)	continue ;;
+		*)		${TEST} ! -d "$dir" && continue ;;
+		esac
+		case $d_flags in
+		*o*)	;;
+		*)	continue ;;
+		esac
+		shadow_dir="${PKG_REFCOUNT_DBDIR}$dir"
+		${TEST} -d "$shadow_dir" && continue	# refcount isn't zero
+		case "$printed_header" in
+		yes)	;;
+		*)	printed_header=yes
+			${ECHO} "==========================================================================="
+			${ECHO} "The following directories are no longer being used by ${PKGNAME},"
+			${ECHO} "and they can be removed if no other packages are using them:"
+			${ECHO} ""
+			;;
+		esac
+		${ECHO} "	${dir}"
+	done
+	case "$printed_header" in
+	yes)	${ECHO} ""
+		${ECHO} "==========================================================================="
+		;;
+	esac; }
+	;;
+
+*)
+	${ECHO} "Usage: ./+DIRS ADD|REMOVE [metadatadir]"
+	${ECHO} "       ./+DIRS CHECK-ADD|CHECK-REMOVE"
+	;;
+esac
Index: install/header
===================================================================
RCS file: /cvsroot/pkgsrc/mk/install/header,v
retrieving revision 1.27
diff -u -r1.27 header
--- install/header	27 Dec 2004 06:41:50 -0000	1.27
+++ install/header	26 Jan 2005 23:18:33 -0000
@@ -35,6 +35,7 @@
 PERL5="@PERL5@"
 PKG_ADMIN="@PKG_ADMIN@"
 PKG_INFO="@PKG_INFO@"
+PWD_CMD="@PWD_CMD@"
 RM="@RM@"
 RMDIR="@RMDIR@"
 SED="@SED@"
@@ -49,6 +50,7 @@
 USERADD="@USERADD@"
 XARGS="@XARGS@"
 
+: ${PKG_METADATA_DIR=`${PWD_CMD}`}
 PKGBASE="@PKGBASE@"
 
 LOCALBASE="@LOCALBASE@"
@@ -74,11 +76,6 @@
 RCD_SCRIPTS_DIR="@RCD_SCRIPTS_DIR@"
 RCD_SCRIPTS_EXAMPLEDIR="@RCD_SCRIPTS_EXAMPLEDIR@"
 
-MAKE_DIRS="@MAKE_DIRS@"
-MAKE_DIRS_PERMS="@MAKE_DIRS_PERMS@"
-OWN_DIRS="@OWN_DIRS@"
-OWN_DIRS_PERMS="@OWN_DIRS_PERMS@"
-
 PKG_SYSCONFBASE="@PKG_SYSCONFBASE@"
 PKG_SYSCONFDEPOTBASE="@PKG_SYSCONFDEPOTBASE@"
 PKG_SYSCONFBASEDIR="@PKG_SYSCONFBASEDIR@"
@@ -96,8 +93,6 @@
 ALL_USERS=
 ALL_GROUPS=
 ALL_FILES=
-ALL_MAKE_DIRS=
-ALL_DIRS=
 VIEW_FILES=
 
 CONF_IGNORE_FILES="*[~#] *.OLD *.orig *,v .pkgsrc */.pkgsrc"
Index: install/install
===================================================================
RCS file: /cvsroot/pkgsrc/mk/install/install,v
retrieving revision 1.33
diff -u -r1.33 install
--- install/install	6 Jan 2005 23:44:35 -0000	1.33
+++ install/install	26 Jan 2005 23:18:34 -0000
@@ -2,20 +2,6 @@
 #
 # $NetBSD: install,v 1.33 2005/01/06 23:44:35 jlam Exp $
 
-if [ -z "${CONF_FILES}" -a -z "${CONF_FILES_PERMS}" -a			\
-     -z "${SUPPORT_FILES}" -a -z "${SUPPORT_FILES_PERMS}" -o		\
-     "${_PKG_CONFIG}" = "NO" ]; then
-	:
-else
-	MAKE_DIRS="${MAKE_DIRS} \"${PKG_SYSCONFDIR}\""
-fi
-
-if [ -z "${RCD_SCRIPTS}" -o "${_PKG_RCD_SCRIPTS}" = "NO" ]; then
-	:
-else
-	MAKE_DIRS="${MAKE_DIRS} \"${RCD_SCRIPTS_DIR}\""
-fi
-
 case ${STAGE} in
 PRE-INSTALL)
 	msginit
@@ -131,97 +117,18 @@
 			${LN} -sf $sysconfdir ${PKG_SYSCONFDIR}
 		fi
 	fi
-	if [ -n "${MAKE_DIRS}" -o -n "${OWN_DIRS}" -o			\
-	     -n "${MAKE_DIRS_PERMS}" -o -n "${OWN_DIRS_PERMS}" ]; then
-		eval set -- ${MAKE_DIRS} ${OWN_DIRS}
-		for dir; do
-			if [ -d "${dir}" ]; then
-				continue
-			fi
-			if [ "${_PKG_CONFIG}" = "YES" ]; then
-				${MKDIR} "${dir}"
-				if [ "${PKG_INSTALLATION_TYPE}" = "pkgviews" ]; then
-					case "${dir}" in
-					${PKG_PREFIX}|${PKG_PREFIX}/*)	;;
-					*)	${ECHO} "${PKGBASE}" > "${dir}/.pkgsrc" ;;
-					esac
-				else
-					${ECHO} "${PKGBASE}" > "${dir}/.pkgsrc"
-				fi
-			fi
-		done
-		eval set -- ${MAKE_DIRS_PERMS} ${OWN_DIRS_PERMS}
-		while [ $# -gt 0 ]; do
-			dir="$1"; owner="$2"; group="$3"; mode="$4"
-			shift; shift; shift; shift
-			if [ "${_PKG_CONFIG}" = "YES" ]; then
-				if [ ! -d "${dir}" ]; then
-					${MKDIR} "${dir}"
-					if [ "${PKG_INSTALLATION_TYPE}" = "pkgviews" ]; then
-						case "${dir}" in
-						${PKG_PREFIX}|${PKG_PREFIX}/*)	;;
-						*)	${ECHO} "${PKGBASE}" > "${dir}/.pkgsrc" ;;
-						esac
-					else
-						${ECHO} "${PKGBASE}" > "${dir}/.pkgsrc"
-					fi
-					${CHOWN} -R "${owner}" "${dir}"
-					${CHGRP} -R "${group}" "${dir}"
-					${CHMOD} -R "${mode}" "${dir}"
-				fi
-			fi
-		done
-	fi
-	if ! msgempty; then
-		${ECHO} "==========================================================================="
-		msgprint
-		${ECHO} ""
-		${ECHO} "==========================================================================="
-	fi
-	if [ ${_pkg_exit} -gt 0 ]; then
-		exit ${_pkg_exit}
-	fi
+	case ${_PKG_CONFIG} in
+        YES)	${TEST} -x ./+DIRS && ./+DIRS ADD ${PKG_METADATA_DIR} ;;
+        esac
         ;;
 
 POST-INSTALL)
 	#
 	# Note any missing package directories.
 	#
-	msginit
-	if [ -n "${MAKE_DIRS}" -o -n "${OWN_DIRS}" -o			\
-	     -n "${MAKE_DIRS_PERMS}" -o -n "${OWN_DIRS_PERMS}" ]; then
-		_print_dir_header=1
-		eval set -- ${MAKE_DIRS} ${OWN_DIRS}
-		for dir; do
-			if [ -d "${dir}" ]; then
-				continue
-			fi
-			if [ "${_PKG_CONFIG}" = "NO" ]; then
-				if [ ${_print_dir_header} -gt 0 ]; then
-					_print_dir_header=0
-					msgadd ""
-					msgadd "The following directories should be created for ${PKGNAME}:"
-					msgadd ""
-				fi
-				msgadd "#${dir}"
-			fi
-		done
-		eval set -- ${MAKE_DIRS_PERMS} ${OWN_DIRS_PERMS}
-		while [ $# -gt 0 ]; do
-			dir="$1"; owner="$2"; group="$3"; mode="$4"
-			shift; shift; shift; shift
-			if [ "${_PKG_CONFIG}" = "NO" ]; then
-				if [ ${_print_dir_header} -gt 0 ]; then
-					_print_dir_header=0
-					msgadd ""
-					msgadd "The following directories should be created for ${PKGNAME}:"
-					msgadd ""
-				fi
-				msgadd "#${dir} (o=${owner}, g=${group}, m=${mode})"
-			fi
-		done
-	fi
+	${TEST} -x ./+DIRS && ./+DIRS CHECK-ADD
 
+	msginit
 	if [ "${_PKG_CONFIG}" = "YES" ]; then
 		if [ -n "${CONF_FILES}" -o				\
 		     -n "${CONF_FILES_PERMS}" -o			\

--6TrnltStXW4iwmi0--