Implement the rest of package updating.
authorKristian H?gsberg <krh@redhat.com>
Thu Sep 20 14:21:28 2007 -0400 (2007-09-20)
changeset 37094daff9a8dc
parent 36 266dba01582d
child 38 88f3ec190a3f
Implement the rest of package updating.
Makefile
razor.c
     1.1 --- a/Makefile	Wed Sep 19 23:24:57 2007 -0400
     1.2 +++ b/Makefile	Thu Sep 20 14:21:28 2007 -0400
     1.3 @@ -1,4 +1,4 @@
     1.4 -CFLAGS = -Wall -g -O2
     1.5 +CFLAGS = -Wall -g
     1.6  LDLIBS = -lexpat -g -lrpm
     1.7  
     1.8  razor : razor.o import.o sha1.o
     2.1 --- a/razor.c	Wed Sep 19 23:24:57 2007 -0400
     2.2 +++ b/razor.c	Thu Sep 20 14:21:28 2007 -0400
     2.3 @@ -914,10 +914,17 @@
     2.4  	for (r = set->requires.data; r < rend; r++) {
     2.5  		while (p < pend && strcmp(&pool[r->name], &pool[p->name]) > 0)
     2.6  			p++;
     2.7 +
     2.8  		/* If there is more than one version of a provides,
     2.9  		 * seek to the end for the highest version. */
    2.10  		while (p + 1 < pend && p->name == (p + 1)->name)
    2.11  			p++;
    2.12 +
    2.13 +		/* FIXME: We need to track property flags (<, <=, =
    2.14 +		 * etc) to properly determine if a requires is
    2.15 +		 * satisfied.  The current code doesn't track that the
    2.16 +		 * requires a = 1 isn't satisfied by a = 2 provides. */
    2.17 +
    2.18  		if (p == pend || strcmp(&pool[r->name], &pool[p->name]) != 0 ||
    2.19  		    versioncmp(&pool[r->version], &pool[p->version]) > 0) {
    2.20  			/* FIXME: We ignore file requires for now. */
    2.21 @@ -1023,8 +1030,9 @@
    2.22  
    2.23  	while (s < send) {
    2.24  		p = upstream_packages + *u;
    2.25 -		cmp = strcmp(&spool[s->name], &upool[p->name]);
    2.26 -		if (cmp < 0 || u == uend) {
    2.27 +		if (u < uend)
    2.28 +			cmp = strcmp(&spool[s->name], &upool[p->name]);
    2.29 +		if (u >= uend || cmp < 0) {
    2.30  			add_package(importer, s, set);
    2.31  			s++;
    2.32  		} else if (cmp == 0) {
    2.33 @@ -1040,13 +1048,57 @@
    2.34  	return razor_importer_finish(importer);
    2.35  }
    2.36  
    2.37 +void
    2.38 +razor_set_satisfy(struct razor_set *set, struct array *unsatisfied,
    2.39 +		  struct razor_set *upstream, struct array *list)
    2.40 +{
    2.41 +	struct razor_property *requires, *r;
    2.42 +	struct razor_property *p, *pend;
    2.43 +	unsigned long *u, *end, *pkg, *property_pool;
    2.44 +	char *pool, *upool;
    2.45 +
    2.46 +	end = unsatisfied->data + unsatisfied->size;
    2.47 +	requires = set->requires.data;
    2.48 +	pool = set->string_pool.data;
    2.49 +
    2.50 +	p = upstream->provides.data;
    2.51 +	pend = upstream->provides.data + upstream->provides.size;
    2.52 +	upool = upstream->string_pool.data;
    2.53 +	property_pool = upstream->property_pool.data;
    2.54 +
    2.55 +	for (u = unsatisfied->data; u < end; u++) {
    2.56 +		r = requires + *u;
    2.57 +
    2.58 +		while (p < pend && strcmp(&pool[r->name], &upool[p->name]) > 0)
    2.59 +			p++;
    2.60 +		/* If there is more than one version of a provides,
    2.61 +		 * seek to the end for the highest version. */
    2.62 +		while (p + 1 < pend && p->name == (p + 1)->name)
    2.63 +			p++;
    2.64 +
    2.65 +		if (p == pend ||
    2.66 +		    strcmp(&pool[r->name], &upool[p->name]) != 0 ||
    2.67 +		    versioncmp(&pool[r->version], &upool[p->version]) > 0) {
    2.68 +			/* Do we need to track unsatisfiable requires
    2.69 +			 * as we go, or should we just do a
    2.70 +			 * razor_set_validate() at the end? */
    2.71 +		} else {
    2.72 +			pkg = array_add(list, sizeof *pkg);
    2.73 +			/* We just pull in the first package that provides */
    2.74 +			*pkg = property_pool[p->packages];
    2.75 +		}
    2.76 +	}	
    2.77 +}
    2.78 +
    2.79  struct razor_set *
    2.80  razor_set_update(struct razor_set *set, struct razor_set *upstream,
    2.81  		 int count, const char **packages)
    2.82  {
    2.83 -	struct razor_package *p;
    2.84 -	struct array list;
    2.85 -	unsigned long *r;
    2.86 +	struct razor_set *new;
    2.87 +	struct razor_package *p, *upackages;
    2.88 +	struct array list, unsatisfied;
    2.89 +	char *pool;
    2.90 +	unsigned long *r, *u, *end;
    2.91  	int i;
    2.92  
    2.93  	array_init(&list);
    2.94 @@ -1056,7 +1108,42 @@
    2.95  		*r = p - (struct razor_package *) upstream->packages.data;
    2.96  	}
    2.97  
    2.98 -	return razor_set_add(set, upstream, &list);
    2.99 +	end = list.data + list.size;
   2.100 +	upackages = upstream->packages.data;
   2.101 +	pool = upstream->string_pool.data;
   2.102 +	for (u = list.data; u < end; u++) {
   2.103 +		p = upackages + *u;
   2.104 +		printf("package %s-%s set to be updated\n",
   2.105 +		       &pool[p->name], &pool[p->version]);
   2.106 +	}
   2.107 +
   2.108 +	while (list.size > 0) {
   2.109 +		printf(" -- satisfying new requires\n");
   2.110 +
   2.111 +		new = razor_set_add(set, upstream, &list);
   2.112 +		array_release(&list);
   2.113 +		razor_set_destroy(set);
   2.114 +		set = new;
   2.115 +
   2.116 +		array_init(&unsatisfied);
   2.117 +		razor_set_validate(new, &unsatisfied);
   2.118 +		array_init(&list);
   2.119 +		razor_set_satisfy(new, &unsatisfied, upstream, &list);
   2.120 +		array_release(&unsatisfied);
   2.121 +
   2.122 +		end = list.data + list.size;
   2.123 +		upackages = upstream->packages.data;
   2.124 +		pool = upstream->string_pool.data;
   2.125 +		for (u = list.data; u < end; u++) {
   2.126 +			p = upackages + *u;
   2.127 +			printf("package %s-%s set to be updated\n",
   2.128 +			       &pool[p->name], &pool[p->version]);
   2.129 +		}
   2.130 +	}
   2.131 +
   2.132 +	array_release(&list);
   2.133 +
   2.134 +	return set;
   2.135  }
   2.136  
   2.137  void
   2.138 @@ -1103,7 +1190,7 @@
   2.139  int
   2.140  main(int argc, const char *argv[])
   2.141  {
   2.142 -	struct razor_set *set, *upstream, *new;
   2.143 +	struct razor_set *set, *upstream;
   2.144  	struct stat statbuf;
   2.145  	char *repo;
   2.146  
   2.147 @@ -1184,11 +1271,11 @@
   2.148  		upstream = razor_set_open(rawhide_repo_filename);
   2.149  		if (set == NULL || upstream == NULL)
   2.150  			return 1;
   2.151 -		new = razor_set_update(set, upstream, argc - 2, argv + 2);
   2.152 -		razor_set_write(new, "system-updated.repo");
   2.153 -		razor_set_destroy(new);
   2.154 +		set = razor_set_update(set, upstream, argc - 2, argv + 2);
   2.155 +		razor_set_write(set, "system-updated.repo");
   2.156  		razor_set_destroy(set);
   2.157  		razor_set_destroy(upstream);
   2.158 +		printf("wrote system-updated.repo\n");
   2.159  	} else {
   2.160  		usage();
   2.161  	}