Fix bug causing multiple installs to abort
authorJ. Ali Harlow <ali@juiblex.co.uk>
Thu Oct 01 19:54:03 2009 +0100 (2009-10-01)
changeset 387ef9237601f24
parent 386 3d3fab314c4e
child 388 6a6462ce8a08
Fix bug causing multiple installs to abort
librazor/razor.c
test/Makefile.am
test/mult-install.sh
     1.1 --- a/librazor/razor.c	Mon Sep 28 17:37:12 2009 +0100
     1.2 +++ b/librazor/razor.c	Thu Oct 01 19:54:03 2009 +0100
     1.3 @@ -704,6 +704,32 @@
     1.4  	razor_file_iterator_destroy(fi);
     1.5  }
     1.6  
     1.7 +/*
     1.8 + * Package data can potentially come from two places. The so-called
     1.9 + * metadata (eg., from comps.xml) and from an RPM file. We consider
    1.10 + * a package which has additional data from an RPM file as "fixed".
    1.11 + * If a package needs fixing, then razor_transaction_fixup_package()
    1.12 + * will do so. When considering what packages to add and to remove
    1.13 + * we need to take this into account since we always want to add
    1.14 + * unfixed packages (otherwise we have a potential conflict between
    1.15 + * the existing package data and that present in the RPM).
    1.16 + */
    1.17 +static int
    1.18 +razor_package_is_fixed(struct razor_set *set, struct razor_package *p)
    1.19 +{
    1.20 +	const char *preunprog, *preun, *postunprog, *postun;
    1.21 +
    1.22 +	if (!p)
    1.23 +		return 0;
    1.24 +	razor_package_get_details(set, p,
    1.25 +				  RAZOR_DETAIL_PREUNPROG, &preunprog,
    1.26 +				  RAZOR_DETAIL_PREUN, &preun,
    1.27 +				  RAZOR_DETAIL_POSTUNPROG, &postunprog,
    1.28 +				  RAZOR_DETAIL_POSTUN, &postun,
    1.29 +				  RAZOR_DETAIL_LAST);
    1.30 +	return *preunprog || *preun || *postunprog || *postun;
    1.31 +}
    1.32 +
    1.33  RAZOR_EXPORT void
    1.34  razor_set_diff(struct razor_set *set, struct razor_set *upstream,
    1.35  	       razor_diff_callback_t callback, void *data)
    1.36 @@ -711,7 +737,7 @@
    1.37   	struct razor_package_iterator *pi1, *pi2;
    1.38   	struct razor_package *p1, *p2;
    1.39  	const char *name1, *name2, *version1, *version2, *arch1, *arch2;
    1.40 -	int res;
    1.41 +	int res, is_fixed1, is_fixed2;
    1.42  
    1.43  	assert (set != NULL);
    1.44  	assert (upstream != NULL);
    1.45 @@ -724,17 +750,21 @@
    1.46  				    RAZOR_DETAIL_VERSION, &version1,
    1.47  				    RAZOR_DETAIL_ARCH, &arch1,
    1.48  				    RAZOR_DETAIL_LAST);
    1.49 +	is_fixed1 = razor_package_is_fixed(set, p1);
    1.50  	razor_package_iterator_next(pi2, &p2,
    1.51  				    RAZOR_DETAIL_NAME, &name2,
    1.52  				    RAZOR_DETAIL_VERSION, &version2,
    1.53  				    RAZOR_DETAIL_ARCH, &arch2,
    1.54  				    RAZOR_DETAIL_LAST);
    1.55 +	is_fixed2 = razor_package_is_fixed(upstream, p2);
    1.56  
    1.57  	while (p1 || p2) {
    1.58  		if (p1 && p2) {
    1.59  			res = strcmp(name1, name2);
    1.60  			if (res == 0)
    1.61  				res = razor_versioncmp(version1, version2);
    1.62 +			if (res == 0)
    1.63 +				res = is_fixed1 - is_fixed2;
    1.64  		} else {
    1.65  			res = 0;
    1.66  		}
    1.67 @@ -746,18 +776,22 @@
    1.68  			callback(RAZOR_DIFF_ACTION_ADD,
    1.69  				 p2, name2, version2, arch2, data);
    1.70  
    1.71 -		if (p1 != NULL && res <= 0)
    1.72 +		if (p1 != NULL && res <= 0) {
    1.73  			razor_package_iterator_next(pi1, &p1,
    1.74  						    RAZOR_DETAIL_NAME, &name1,
    1.75  						    RAZOR_DETAIL_VERSION, &version1,
    1.76  						    RAZOR_DETAIL_ARCH, &arch1,
    1.77  						    RAZOR_DETAIL_LAST);
    1.78 -		if (p2 != NULL && res >= 0)
    1.79 +			is_fixed1 = razor_package_is_fixed(set, p1);
    1.80 +		}
    1.81 +		if (p2 != NULL && res >= 0) {
    1.82  			razor_package_iterator_next(pi2, &p2,
    1.83  						    RAZOR_DETAIL_NAME, &name2,
    1.84  						    RAZOR_DETAIL_VERSION, &version2,
    1.85  						    RAZOR_DETAIL_ARCH, &arch2,
    1.86  						    RAZOR_DETAIL_LAST);
    1.87 +			is_fixed2 = razor_package_is_fixed(upstream, p2);
    1.88 +		}
    1.89  	}
    1.90  
    1.91  	razor_package_iterator_destroy(pi1);
     2.1 --- a/test/Makefile.am	Mon Sep 28 17:37:12 2009 +0100
     2.2 +++ b/test/Makefile.am	Thu Oct 01 19:54:03 2009 +0100
     2.3 @@ -2,7 +2,7 @@
     2.4  
     2.5  check_SCRIPTS = relocate named-root remove update
     2.6  if HAVE_LUA
     2.7 -  check_SCRIPTS += lua
     2.8 +  check_SCRIPTS += lua mult-install
     2.9  endif
    2.10  check_SCRIPTS += order
    2.11  
    2.12 @@ -24,6 +24,9 @@
    2.13  lua:	lua.sh primary.xml.gz
    2.14  	cp $(srcdir)/lua.sh lua
    2.15  
    2.16 +mult-install:	mult-install.sh primary.xml.gz
    2.17 +	cp $(srcdir)/mult-install.sh mult-install
    2.18 +
    2.19  base/repodata/primary.xml.gz:	zsh.spec zsh2.spec zip.spec zap.spec \
    2.20  		filesystem.spec Makefile
    2.21  	rm -rf rpmbuild base
    2.22 @@ -63,6 +66,7 @@
    2.23  	zsh2.spec		\
    2.24  	filesystem.spec		\
    2.25  	order.sh		\
    2.26 +	mult-install.sh		\
    2.27  	lua.sh			\
    2.28  	remove.sh		\
    2.29  	update.sh		\
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/mult-install.sh	Thu Oct 01 19:54:03 2009 +0100
     3.3 @@ -0,0 +1,75 @@
     3.4 +#!/bin/sh
     3.5 +fs_check_file()
     3.6 +{
     3.7 +    if [ ! -e "$RAZOR_ROOT$1" ]; then 
     3.8 +	echo $1: Not in filesystem >&2
     3.9 +	ls -R "$RAZOR_ROOT" >&2
    3.10 +	exit 1
    3.11 +    fi
    3.12 +}
    3.13 +fs_check_file_contents()
    3.14 +{
    3.15 +    fs_check_file "$1"
    3.16 +    if [ `cat "$RAZOR_ROOT$1"` != "$2" ]; then
    3.17 +	echo $1: Unexpected contents >&2
    3.18 +	cat "$RAZOR_ROOT$1" >&2
    3.19 +	exit 1
    3.20 +    fi
    3.21 +}
    3.22 +fs_check_no_file()
    3.23 +{
    3.24 +    if [ -e "$RAZOR_ROOT$1" ]; then 
    3.25 +	echo $1: Still in filesystem >&2
    3.26 +	exit 1
    3.27 +    fi
    3.28 +}
    3.29 +check_file()
    3.30 +{
    3.31 +    ../src/razor list-files | grep -x "$1" > /dev/null
    3.32 +    if [ $? -ne 0 ]; then
    3.33 +	echo $1: Not in database >&2
    3.34 +	../src/razor list-files >&2
    3.35 +	exit 1
    3.36 +    fi
    3.37 +    ../src/razor list-files "$1" | grep -x "$1" > /dev/null
    3.38 +    if [ $? -ne 0 ]; then
    3.39 +	echo $1: Not seen by patterned list >&2
    3.40 +	../src/razor list-files "$1" >&2
    3.41 +	exit 1
    3.42 +    fi
    3.43 +    pkgs=`../src/razor list-file-packages "$1"`
    3.44 +    if [ -z "$pkgs" ]; then
    3.45 +	echo $1: Not owned by any package >&2
    3.46 +	../src/razor list-file-packages "$1"
    3.47 +	exit 1
    3.48 +    fi
    3.49 +    for nevra in "$pkgs"; do
    3.50 +	name=`echo $nevra | sed 's/\-.*$//'`
    3.51 +	../src/razor list-package-files "$name" | grep -x "$1" > /dev/null
    3.52 +	if [ $? -ne 0 ]; then
    3.53 +	    echo $1: Not in database for package $name >&2
    3.54 +	    ../src/razor list-package-files "$name"
    3.55 +	    exit 1
    3.56 +	fi
    3.57 +    done
    3.58 +    fs_check_file $1
    3.59 +}
    3.60 +check_no_file()
    3.61 +{
    3.62 +    ../src/razor list-files | grep -x "$1" > /dev/null
    3.63 +    if [ $? -eq 0 ]; then
    3.64 +	echo $1: Still in database >&2
    3.65 +	exit 1
    3.66 +    fi
    3.67 +    fs_check_no_file $1
    3.68 +}
    3.69 +export RAZOR_ROOT=`mktemp -dt` || exit 1
    3.70 +../src/razor init || exit 1
    3.71 +export YUM_URL="file://localhost/`pwd`"
    3.72 +../src/razor import-yum || exit 1
    3.73 +../src/razor install --relocate /usr=/opt zip || exit 1
    3.74 +fs_check_file_contents /opt/bin/zip zip-1-1
    3.75 +fs_check_file /opt/var/lib/zip/data.zap
    3.76 +../src/razor install --relocate /usr=/opt zip || exit 1
    3.77 +../src/razor install --relocate /usr=/opt zip || exit 1
    3.78 +rm -rf "$RAZOR_ROOT"