NetBSD Problem Report #45079

From www@NetBSD.org  Fri Jun 17 15:03:14 2011
Return-Path: <www@NetBSD.org>
Received: from mail.netbsd.org (mail.netbsd.org [204.152.190.11])
	by www.NetBSD.org (Postfix) with ESMTP id 34FB563C6C2
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 17 Jun 2011 15:03:14 +0000 (UTC)
Message-Id: <20110617150312.E819963C1C3@www.NetBSD.org>
Date: Fri, 17 Jun 2011 15:03:12 +0000 (UTC)
From: tcort@minix3.org
Reply-To: tcort@minix3.org
To: gnats-bugs@NetBSD.org
Subject: mk/pkginstall/{dirs,files} handle PKG_DESTDIR
X-Send-Pr-Version: www-1.0

>Number:         45079
>Category:       pkg
>Synopsis:       mk/pkginstall/{dirs,files} handle PKG_DESTDIR
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    pkg-manager
>State:          open
>Class:          change-request
>Submitter-Id:   net
>Arrival-Date:   Fri Jun 17 15:05:00 +0000 2011
>Originator:     Thomas Cort
>Release:        N/A
>Organization:
Minix3
>Environment:
Minix 192.168.122.210 3.2.0 i686
>Description:
PKG_DESTDIR is set by pkg_add and pkg_delete when called with the -P 
option. Without these changes (see patch below) packages installed
using the -P option would have a +DIRS script that manipulates the
wrong set of directories. The files script is changed similarly.

To explain a little on what's going on: Packages have install and 
desintall scripts that are run by pkg_install tools before and after 
installation and deletion. Because of this the +DIRS script which is 
generated from the mk/pkginstall/dirs file gets executed. Now pkg_add can
be called with -P option to ask it to install stuff in a different root 
directory. When this is done pkg_add sets the PKG_DESTDIR variable. 
Earlier, the scripts just ignored this variable and these changes make 
them honor it. Similarly, the changes to the files script make it
honor PKG_DESTDIR.

This patch was moved from pkg/45046 so that the PR would
only deal with one problem.
>How-To-Repeat:
Run pkg_add with the -P option.
>Fix:
diff --git a/mk/pkginstall/dirs b/mk/pkginstall/dirs
index c783cbf..611be47 100644
--- a/mk/pkginstall/dirs
+++ b/mk/pkginstall/dirs
@@ -77,6 +77,12 @@ PKG_METADATA_DIR="${2-${CURDIR}}"

 PKG_REFCOUNT_DIRS_DBDIR="${PKG_REFCOUNT_DBDIR}/dirs"

+if ${TEST} -n "${PKG_DESTDIR}"; then
+	PKG_DBDIR="${PKG_DESTDIR}${PKG_DBDIR}"
+	PKG_REFCOUNT_DBDIR="${PKG_DESTDIR}${PKG_REFCOUNT_DBDIR}"
+	PKG_REFCOUNT_DIRS_DBDIR="${PKG_DESTDIR}${PKG_REFCOUNT_DIRS_DBDIR}"
+fi
+
 case "${PKG_CONFIG:-@PKG_CONFIG@}" in
 [Yy][Ee][Ss]|[Tt][Rr][Uu][Ee]|[Oo][Nn]|1)
 	_PKG_CONFIG=yes
@@ -111,6 +117,7 @@ ADD)
 		perms="$shadow_dir/+PERMISSIONS"
 		preexist="$shadow_dir/+PREEXISTING"
 		token="$shadow_dir/${PKGNAME}"
+		dir="${PKG_DESTDIR}$dir"
 		if ${TEST} ! -d "$shadow_dir"; then
 			${MKDIR} $shadow_dir
 			${TEST} ! -d "$dir" ||
@@ -162,6 +169,7 @@ REMOVE)
 		preexist="$shadow_dir/+PREEXISTING"
 		token="$shadow_dir/${PKGNAME}"
 		tokentmp="$token.tmp.$$"
+		dir="${PKG_DESTDIR}$dir"
 		if ${TEST} -f "$token" && \
 		   ${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then
 			${CAT} "$token" | ${GREP} -v "^${PKG_METADATA_DIR}$" > $tokentmp
@@ -193,7 +201,7 @@ PERMS)
 		esac
 		case $dir in
 		"")	continue ;;
-		[!/]*)	dir="${PKG_PREFIX}/$dir" ;;
+		[!/]*)	dir="${PKG_DESTDIR}${PKG_PREFIX}/$dir" ;;
 		esac
 		case $d_user in
 		"")	;;
@@ -215,7 +223,7 @@ CHECK-ADD)
 	{ while read dir d_flags d_mode d_user d_group; do
 		case $dir in
 		"")	continue ;;
-		[!/]*)	dir="${PKG_PREFIX}/$dir" ;;
+		[!/]*)	dir="${PKG_DESTDIR}${PKG_PREFIX}/$dir" ;;
 		esac
 		${TEST} ! -d "$dir" || continue
 		case $d_flags in
@@ -262,6 +270,7 @@ CHECK-REMOVE)
 		esac
 		shadow_dir="${PKG_REFCOUNT_DIRS_DBDIR}$dir"
 		${TEST} ! -d "$shadow_dir" || continue	# refcount isn't zero
+		dir="${PKG_DESTDIR}$dir"
 		case "$printed_header" in
 		yes)	;;
 		*)	printed_header=yes
@@ -290,7 +299,7 @@ CHECK-PERMS)
 	{ while read dir d_flags d_mode d_user d_group; do
 		case $dir in
 		"")	continue ;;
-		[!/]*)	dir="${PKG_PREFIX}/$dir" ;;
+		[!/]*)	dir="${PKG_DESTDIR}${PKG_PREFIX}/$dir" ;;
 		esac
 		${TEST} -d "$dir" || continue
 		case $d_user:$d_group:$d_mode in
diff --git a/mk/pkginstall/files b/mk/pkginstall/files
index 15ed967..489c238 100644
--- a/mk/pkginstall/files
+++ b/mk/pkginstall/files
@@ -114,6 +114,12 @@ VIEW-REMOVE)
 	;;
 esac

+if ${TEST} -n "${PKG_DESTDIR}"; then
+	PKG_DBDIR="${PKG_DESTDIR}${PKG_DBDIR}"
+	PKG_REFCOUNT_DBDIR="${PKG_DESTDIR}${PKG_REFCOUNT_DBDIR}"
+	PKG_REFCOUNT_FILES_DBDIR="${PKG_DESTDIR}${PKG_REFCOUNT_FILES_DBDIR}"
+fi
+
 exitcode=0
 case $ACTION in
 ADD)
@@ -136,6 +142,9 @@ ADD)
 		perms="$shadow_dir/+PERMISSIONS"
 		preexist="$shadow_dir/+PREEXISTING"
 		token="$shadow_dir/${PKGNAME}"
+		file="${PKG_DESTDIR}$file"
+		f_eg="${PKG_DESTDIR}$f_eg"
+
 		if ${TEST} ! -d "$shadow_dir"; then
 			${MKDIR} $shadow_dir
 			${TEST} ! -f "$file" ||
@@ -202,6 +211,9 @@ REMOVE)
 		preexist="$shadow_dir/+PREEXISTING"
 		token="$shadow_dir/${PKGNAME}"
 		tokentmp="$token.tmp.$$"
+		file="${PKG_DESTDIR}$file"
+		f_eg="${PKG_DESTDIR}$f_eg"
+
 		if ${TEST} -f "$token" && \
 		   ${GREP} "^${PKG_METADATA_DIR}$" $token >/dev/null; then
 			${CAT} "$token" | ${GREP} -v "^${PKG_METADATA_DIR}$" > $tokentmp
@@ -237,7 +249,7 @@ PERMS)
 		esac
 		case $file in
 		"")	continue ;;
-		[!/]*)	file="${PKG_PREFIX}/$file" ;;
+		[!/]*)	file="${PKG_DESTDIR}${PKG_PREFIX}/$file" ;;
 		esac
 		case $f_user in
 		"")	;;
@@ -275,7 +287,7 @@ CHECK-ADD)
 	{ while read file f_flags f_eg f_mode f_user f_group; do
 		case $file in
 		"")	continue ;;
-		[!/]*)	file="${PKG_PREFIX}/$file" ;;
+		[!/]*)	file="${PKG_DESTDIR}${PKG_PREFIX}/$file" ;;
 		esac
 		${TEST} ! -f "$file" || continue
 		case $f_flags in
@@ -284,7 +296,7 @@ CHECK-ADD)
 		esac
 		case $f_eg in
 		"")	continue ;;
-		[!/]*)	f_eg="${PKG_PREFIX}/$f_eg" ;;
+		[!/]*)	f_eg="${PKG_DESTDIR}${PKG_PREFIX}/$f_eg" ;;
 		esac

 		case "$printed_header" in
@@ -330,6 +342,8 @@ CHECK-REMOVE)
 		${TEST} -f "$file" || continue
 		shadow_dir="${PKG_REFCOUNT_FILES_DBDIR}$file"
 		${TEST} ! -d "$shadow_dir" || continue	# refcount isn't zero
+		file="${PKG_DESTDIR}$file"
+
 		case "$printed_header" in
 		yes)	;;
 		*)	printed_header=yes
@@ -358,7 +372,7 @@ CHECK-PERMS)
 	{ while read file f_flags f_eg f_mode f_user f_group; do
 		case $file in
 		"")	continue ;;
-		[!/]*)	file="${PKG_PREFIX}/$file" ;;
+		[!/]*)	file="${PKG_DESTDIR}${PKG_PREFIX}/$file" ;;
 		esac
 		${TEST} -f "$file" || continue
 		case $f_mode:$f_user:$f_group in

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.39 2013/11/01 18:47:49 spz Exp $
$NetBSD: gnats_config.sh,v 1.8 2006/05/07 09:23:38 tsutsui Exp $
Copyright © 1994-2007 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.