razor.c
changeset 37 094daff9a8dc
parent 36 266dba01582d
child 38 88f3ec190a3f
     1.1 --- a/razor.c	Wed Sep 19 23:24:57 2007 -0400
     1.2 +++ b/razor.c	Thu Sep 20 14:21:28 2007 -0400
     1.3 @@ -914,10 +914,17 @@
     1.4  	for (r = set->requires.data; r < rend; r++) {
     1.5  		while (p < pend && strcmp(&pool[r->name], &pool[p->name]) > 0)
     1.6  			p++;
     1.7 +
     1.8  		/* If there is more than one version of a provides,
     1.9  		 * seek to the end for the highest version. */
    1.10  		while (p + 1 < pend && p->name == (p + 1)->name)
    1.11  			p++;
    1.12 +
    1.13 +		/* FIXME: We need to track property flags (<, <=, =
    1.14 +		 * etc) to properly determine if a requires is
    1.15 +		 * satisfied.  The current code doesn't track that the
    1.16 +		 * requires a = 1 isn't satisfied by a = 2 provides. */
    1.17 +
    1.18  		if (p == pend || strcmp(&pool[r->name], &pool[p->name]) != 0 ||
    1.19  		    versioncmp(&pool[r->version], &pool[p->version]) > 0) {
    1.20  			/* FIXME: We ignore file requires for now. */
    1.21 @@ -1023,8 +1030,9 @@
    1.22  
    1.23  	while (s < send) {
    1.24  		p = upstream_packages + *u;
    1.25 -		cmp = strcmp(&spool[s->name], &upool[p->name]);
    1.26 -		if (cmp < 0 || u == uend) {
    1.27 +		if (u < uend)
    1.28 +			cmp = strcmp(&spool[s->name], &upool[p->name]);
    1.29 +		if (u >= uend || cmp < 0) {
    1.30  			add_package(importer, s, set);
    1.31  			s++;
    1.32  		} else if (cmp == 0) {
    1.33 @@ -1040,13 +1048,57 @@
    1.34  	return razor_importer_finish(importer);
    1.35  }
    1.36  
    1.37 +void
    1.38 +razor_set_satisfy(struct razor_set *set, struct array *unsatisfied,
    1.39 +		  struct razor_set *upstream, struct array *list)
    1.40 +{
    1.41 +	struct razor_property *requires, *r;
    1.42 +	struct razor_property *p, *pend;
    1.43 +	unsigned long *u, *end, *pkg, *property_pool;
    1.44 +	char *pool, *upool;
    1.45 +
    1.46 +	end = unsatisfied->data + unsatisfied->size;
    1.47 +	requires = set->requires.data;
    1.48 +	pool = set->string_pool.data;
    1.49 +
    1.50 +	p = upstream->provides.data;
    1.51 +	pend = upstream->provides.data + upstream->provides.size;
    1.52 +	upool = upstream->string_pool.data;
    1.53 +	property_pool = upstream->property_pool.data;
    1.54 +
    1.55 +	for (u = unsatisfied->data; u < end; u++) {
    1.56 +		r = requires + *u;
    1.57 +
    1.58 +		while (p < pend && strcmp(&pool[r->name], &upool[p->name]) > 0)
    1.59 +			p++;
    1.60 +		/* If there is more than one version of a provides,
    1.61 +		 * seek to the end for the highest version. */
    1.62 +		while (p + 1 < pend && p->name == (p + 1)->name)
    1.63 +			p++;
    1.64 +
    1.65 +		if (p == pend ||
    1.66 +		    strcmp(&pool[r->name], &upool[p->name]) != 0 ||
    1.67 +		    versioncmp(&pool[r->version], &upool[p->version]) > 0) {
    1.68 +			/* Do we need to track unsatisfiable requires
    1.69 +			 * as we go, or should we just do a
    1.70 +			 * razor_set_validate() at the end? */
    1.71 +		} else {
    1.72 +			pkg = array_add(list, sizeof *pkg);
    1.73 +			/* We just pull in the first package that provides */
    1.74 +			*pkg = property_pool[p->packages];
    1.75 +		}
    1.76 +	}	
    1.77 +}
    1.78 +
    1.79  struct razor_set *
    1.80  razor_set_update(struct razor_set *set, struct razor_set *upstream,
    1.81  		 int count, const char **packages)
    1.82  {
    1.83 -	struct razor_package *p;
    1.84 -	struct array list;
    1.85 -	unsigned long *r;
    1.86 +	struct razor_set *new;
    1.87 +	struct razor_package *p, *upackages;
    1.88 +	struct array list, unsatisfied;
    1.89 +	char *pool;
    1.90 +	unsigned long *r, *u, *end;
    1.91  	int i;
    1.92  
    1.93  	array_init(&list);
    1.94 @@ -1056,7 +1108,42 @@
    1.95  		*r = p - (struct razor_package *) upstream->packages.data;
    1.96  	}
    1.97  
    1.98 -	return razor_set_add(set, upstream, &list);
    1.99 +	end = list.data + list.size;
   1.100 +	upackages = upstream->packages.data;
   1.101 +	pool = upstream->string_pool.data;
   1.102 +	for (u = list.data; u < end; u++) {
   1.103 +		p = upackages + *u;
   1.104 +		printf("package %s-%s set to be updated\n",
   1.105 +		       &pool[p->name], &pool[p->version]);
   1.106 +	}
   1.107 +
   1.108 +	while (list.size > 0) {
   1.109 +		printf(" -- satisfying new requires\n");
   1.110 +
   1.111 +		new = razor_set_add(set, upstream, &list);
   1.112 +		array_release(&list);
   1.113 +		razor_set_destroy(set);
   1.114 +		set = new;
   1.115 +
   1.116 +		array_init(&unsatisfied);
   1.117 +		razor_set_validate(new, &unsatisfied);
   1.118 +		array_init(&list);
   1.119 +		razor_set_satisfy(new, &unsatisfied, upstream, &list);
   1.120 +		array_release(&unsatisfied);
   1.121 +
   1.122 +		end = list.data + list.size;
   1.123 +		upackages = upstream->packages.data;
   1.124 +		pool = upstream->string_pool.data;
   1.125 +		for (u = list.data; u < end; u++) {
   1.126 +			p = upackages + *u;
   1.127 +			printf("package %s-%s set to be updated\n",
   1.128 +			       &pool[p->name], &pool[p->version]);
   1.129 +		}
   1.130 +	}
   1.131 +
   1.132 +	array_release(&list);
   1.133 +
   1.134 +	return set;
   1.135  }
   1.136  
   1.137  void
   1.138 @@ -1103,7 +1190,7 @@
   1.139  int
   1.140  main(int argc, const char *argv[])
   1.141  {
   1.142 -	struct razor_set *set, *upstream, *new;
   1.143 +	struct razor_set *set, *upstream;
   1.144  	struct stat statbuf;
   1.145  	char *repo;
   1.146  
   1.147 @@ -1184,11 +1271,11 @@
   1.148  		upstream = razor_set_open(rawhide_repo_filename);
   1.149  		if (set == NULL || upstream == NULL)
   1.150  			return 1;
   1.151 -		new = razor_set_update(set, upstream, argc - 2, argv + 2);
   1.152 -		razor_set_write(new, "system-updated.repo");
   1.153 -		razor_set_destroy(new);
   1.154 +		set = razor_set_update(set, upstream, argc - 2, argv + 2);
   1.155 +		razor_set_write(set, "system-updated.repo");
   1.156  		razor_set_destroy(set);
   1.157  		razor_set_destroy(upstream);
   1.158 +		printf("wrote system-updated.repo\n");
   1.159  	} else {
   1.160  		usage();
   1.161  	}