Specs for saving old shared libs

Doug Barton dougb at FreeBSD.org
Sun May 20 04:53:08 UTC 2007


Peter Jeremy wrote:
> On 2007-May-19 16:21:49 -0700, Doug Barton <dougb at freebsd.org> wrote:

>> I still feel that the only safe way to do this is to find the union of 
>> 'ldconfig -r' and 'pkg_info -L' and save those files, and those files only.
> 
> That should be intersection, not union. 

Yeah, that's what I meant, sorry. Too much going on around at home 
today. I was visualizing the intersection, and thinking "where the two 
things come together," which came out "union" somehow.

> I think this makes sense -
> there is no point in backing up private .so files because these should
> only be referenced by the port in question (and therefore the old .so
> files should be unnecessary once the old port version is deleted).

Ok, I've attached the patch that implements this feature for review. A 
full version of portmaster with this, and the other new features is at 
http://dougbarton.us/portmaster

FYI, the bit of this patch that moves 'make clean' to after 'make 
package' is an unrelated bug fix, but it's needed here to make sure 
everything is happening in the right order for delete and install.

Thanks to all those who weighed in,

Doug

-- 

     This .signature sanitized for your protection

-------------- next part --------------
--- portmaster	2007/05/19 22:02:44	1.167
+++ portmaster	2007/05/20 04:35:34	1.168
@@ -2,7 +2,7 @@
 
 # Local version: 1.153
 # $FreeBSD$
-# $Id: portmaster,v 1.167 2007/05/19 22:02:44 doug Exp $
+# $Id: portmaster,v 1.168 2007/05/20 04:35:34 doug Exp $
 
 # Copyright (c) 2005-2007 Douglas Barton, All rights reserved
 # Please see detailed copyright below
@@ -32,7 +32,7 @@
 	echo "portmaster version `grep "[$]FreeBSD:" $0 | cut -d ' ' -f 4`"
 	echo ''
 	echo 'Usage:'
-	echo "Common flags: [--force-config] [-CGgntv B|b uf|i D|d] [-m <arguments for make>]"
+	echo "Common flags: [--force-config] [-CGgntvx B|b uf|i D|d] [-m <arguments for make>]"
 	echo "${0##*/} [Common flags] <full name of port directory in $pdb>"
 	echo "${0##*/} [Common flags] <full path to $pd/foo/bar>"
 	echo "${0##*/} [Common flags] Multiple full names/paths from $pdb|$pd"
@@ -67,6 +67,7 @@
 	echo '-n do not actually make or install any ports'
 	echo '-t recurse dependencies thoroughly, using all-depends-list'
 	echo '-v verbose output'
+	echo '-x save old shared libraries before deinstall'
 	echo "-u unattended mode -- accept defaults for all but 'make config'"
 	echo '-f always rebuild ports (overrides -i)'
 	echo '-i interactive update mode'
@@ -923,7 +924,7 @@
 fi
 
 # Save switches for potential child processes
-while getopts 'BCDGLRabde:fghilm:nop:r:stuv' COMMAND_LINE_ARGUMENT ; do
+while getopts 'BCDGLRabde:fghilm:nop:r:stuvx' COMMAND_LINE_ARGUMENT ; do
 	case "${COMMAND_LINE_ARGUMENT}" in
 	B)	NO_BACKUP=yes; ARGS="-B $ARGS" ;;
 	C)	DONT_PRE_CLEAN=yes; ARGS="-C $ARGS" ;;
@@ -955,6 +956,7 @@
 	t)	RECURSE_THOROUGH=yes; ARGS="-t $ARGS" ;;
 	u)	UNATTENDED=yes; ARGS="-u $ARGS" ;;
 	v)	VERBOSE=yes; ARGS="-v $ARGS" ;;
+	x)	SAVE_SHARED=yes; ARGS="-x $ARGS" ;;
 	*)	usage ;;
 	esac
 done
@@ -1128,6 +1130,9 @@
 	IPC_SAVE=`mktemp -t ipc_save-$PARENT_PID`
 	export CURRENT_DEPS_O CURRENT_DEPS_I IGNOREME_YES DISPLAY_LIST IPC_SAVE
 
+	PORTS_PREFIX=`make $PM_MAKE_ARGS -f$pd/Mk/bsd.port.mk -VPREFIX`
+	export PORTS_PREFIX
+
 	if [ -n "$INTERACTIVE_UPDATE" ]; then
 		INTERACTIVE_YES=':'
 		INTERACTIVE_NO=':'
@@ -1580,6 +1585,21 @@
 	if [ -z "$NO_BACKUP" ]; then
 		backup_package $upg_port
 	fi
+
+	if [ -n "$SAVE_SHARED" ]; then
+		ldconfig_out=`mktemp -t f-${PARENT_PID}-ldconfig`
+		ldconfig -r | sed 's#.* ##' |
+		    grep -v ^${PORTS_PREFIX}/lib/compat > $ldconfig_out
+
+		mkdir -p ${PORTS_PREFIX}/lib/compat/pkg
+
+		for file in `pkg_info -q -L $upg_port | sort - $ldconfig_out | \
+		    uniq -d`; do
+			cp -p $file ${PORTS_PREFIX}/lib/compat/pkg/
+		done
+		ldconfig -m ${PORTS_PREFIX}/lib/compat/pkg
+	fi
+
 	pkg_delete -f $upg_port || fail 'pkg_delete failed'
 
 	if [ -n "$REPLACE_ORIGIN" ]; then
@@ -1590,13 +1610,21 @@
 	fi
 fi
 
-make $PM_MAKE_ARGS install clean NOCLEANDEPENDS=yes || {
+make $PM_MAKE_ARGS install || {
     if [ -z "$NO_BACKUP" -a -n "$upg_port" ]; then
 	echo ''
 	echo "===>>> A backup package for $portdir should be located in $pkgrep"
     fi
     fail "Installation of new port failed";}
 
+# Remove saved libs that match newly installed files
+pkg_info -q -L $new_port | while read file; do
+	if [ -e "${PORTS_PREFIX}/lib/compat/pkg/${file##*/}" ]; then
+		unlink ${PORTS_PREFIX}/lib/compat/pkg/${file##*/}
+	fi
+done
+ldconfig -m ${PORTS_PREFIX}/lib/compat/pkg
+
 # Implement storage of distfile information in the +CONTENTS file in the
 # same way that it will (hopefully, soon?) be implemented in bsd.port.mk
 # See http://www.freebsd.org/cgi/query-pr.cgi?pr=106483
@@ -1619,6 +1647,8 @@
 	make $PM_MAKE_ARGS package || fail 'Package creation of new port failed'
 	echo "	===>>> Package can be found in $pkgrep"
 fi
+
+make $PM_MAKE_ARGS clean NOCLEANDEPENDS=yes
 
 # By now, if this file exists, it should be authoritative
 if [ -s "$req_deps" ]; then


More information about the freebsd-ports mailing list